Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

javascript even/uneven numbers

function getEven(limit = 100, countLimit = true) {
	if (countLimit) {
    	for (let i = 0; i <= limit; i++) {
        	if ((i % 2) === 0) {
            	console.log(`Even: ${i}`)
            }
        }
        return
    }
    
    for (let i = 0; i < limit; i++) {
        if ((i % 2) === 0) {
            console.log(`Even: ${i}`)
        }
    }
}

function getUneven(limit = 100, countLimit = true) {
	if (countLimit) {
    	for (let i = 0; i <= limit; i++) {
        	if ((i % 2) !== 0) {
            	console.log(`Uneven: ${i}`)
            }
        }
        return
    }
    
    for (let i = 0; i < limit; i++) {
        if ((i % 2) !== 0) {
            console.log(`Uneven: ${i}`)
        }
    }
}
 
PREVIOUS NEXT
Tagged: #javascript #numbers
ADD COMMENT
Topic
Name
7+8 =