I don't have any errors in my code, but I do have questions about why the code's syntax is structured this way


#1

Why I am suppose to use the <= ?   


Why am I assigning the var i % 3 
& i % 5 === 0? 

for (var i = 1; i <= 20; 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); 
}
}

#2

So your for loop will run 20 times and then stop.

You are writing that code will post a different text string depending on the value of i as the loop runs. Each time the loop runs, the value of i is increased by 1. If the value of i when divided by 3 leaves a remainder of 0, "Fizz" logs to the console. If the value of i divided by 5 leaves a remainder of 0, "Buzz" logs to the console. If the value of i is a number that can be divided by both 3 and 5 and leaves a remainder of 0, then "FizzBuzz" logs to the console.


#3

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