Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

Using Math Functions in an IF statement

for (i=1; i<21; i++) {

    if(i%3 === 0 && i%5 !== 0) {
        console.log("Fizz");
    } 

    else if (i%5 === 0 && i%3 !== 0) {
        console.log("Buzz");
    }

    else if (i%5 === 0 && !i%3 === 0) {
        console.log("FizzBuzz");
    }
    else {
       console.log(i); 
    }
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #Using #Math #Functions #IF #statement
ADD COMMENT
Topic
Name
2+8 =