question3? i dont understan where the problem is


#1

please help me i ont seem to understand the problem with it.here is my code:
for(var w=1; w>20; w++){
if(w%3===0 ){
console.log("fizz");
}
else if(w%5===0){
console.log("Buzz");
}
else if(w%3===0 && w%5===0){
console.log("FizzBuzz");
}
else{
console.log( w);
}
}


#2

There are two problems.

Let's take a look at your for loop:

for (var w = 1; w > 20; w++) {
    // code
}

w is equal 1, this loop should work as long as w is greater than 20. Do you see a problem? You should change the condition to be initially true. It should be w <= 20.


Ok, let's assume that our w is in this moment equal 15. Your script should print "FizzBuzz", right?

But for w equal 15 condition of the first if (w % 3 === 0) is true. That is why your program will print "fizz" and will continue with the next iteration (w = 16).

Try to fix this problem without our help :smile:


#3

thanks....i have rectified my code here:
for(var w=1; w<=20; w++){
if( w%3===0 && w%5===0){
console.log("FizzBuzz");
}
else if(w%3===0){
console.log("fizz");
}

else if(w%5===0){
    console.log("Buzz");
    }
        else{
            console.log( w);
            }

}

but there is still an error message saying,"Oops, try again.
You printed fizz when you should have printed Fizz
"


#4

Good job!

This problem is pretty easy to fix. Just change this line:

console.log("fizz");

to:

console.log("Fizz");

Codecademy is very case sensitive :smile:


#5

hehehe....thanks yah!! its pretty easy to fix cheers man


#6

You're very welcome :smile: Have a nice day!