3....And the good!


#1

i dont understand where i went wrong here, the editor says that "you printed out the wrong number of items." which i could see and would like to know the error of my code

Replace this line with your code. 
for(var i=0; i<=20; i++){
   
if(i%3===0){
    console.log("Fizz");
    }
    
    else if(i%5===0){
        console.log("Buzz");
        }
        else if(i%3===0 && i%5===0){
            console.log("FizzBuzz");
            }
            else{
                console.log(i);
                }
}


#2

There are 2 things
-1 Start your i-count from 1 instead of you starting from 0

-2 The most specific-test should be =on-Top=
imagine you have to check all =red= =porsche's=, with your logic, you would pull over all =red= cars and all =porsche's=


#3

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

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

}

this is my algorithm for this particular problem. I hope this help you out. Regards


#4

This would be less =CPU= intensive

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

#5

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