Introduction to Objects no. 3


#1

problem too
is my code wrong?
for (num = 1; num === 20; num++) {
console.log(num);
if (num % 3 === 0) {
console.log("Fizz");
} else if (num % 5 === 0) {
console.log("Buzz");
} else if (num % 3 === 0 && num % 5 === 0) {
console.log("FizzBuzz");
} else {
console.log(num);
}
}


Introduction to Objects 3. And the good
#2

The code is:

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); 
        }
    }

#3

Below I wrote the code that I used and it worked, I have no idea what I did, but it worked.

I hope it will work for the people that struggle with this one

for(var i = 1; i < 21; i++) {
if(i%3 === 0 && i%5 === 0){
console.log("FizzBuzz");
}
else if(i%3 === 0 ){
console.log("Fizz");
}
else if(i % 5 === 0){
console.log("Buzz");
}
else{
console.log(i);
}
}


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.