And the Good: Unexpected token ===


#1

My code comes out with the unexpected token ===. I thought 3 equal signs were necessary with any comparison? Also, what exactly does "unexpected token" mean? Any other advice to improve my code is appreciated!

for (var i === 0; i < 21; i++)
{
    console.log(i);
}

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

#2

Your for-loop is wrong. Yes === is for comparison, but for-loop needs assignment. Correct Code:

for (i = 0; i < 21; i++)

#3

okay! I changed my for loop, but now it's telling me I'm printing out the wrong number of items (for either i = 0 or i = 1)


#4

There are many more problems than I initially concieved. Correct code:

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

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

}

#5

Hey @cadecodes :smiley: pls delete that Correct code. People will just use that to pass the excercice. I can explain the errors

So @shilohrohrig first the error is that your not suppose to log console.log(i) like 21 times. Every time you go it should go through your conditons. In your code its not so put your if,else if, and else statements in your for loop. Like this for demo:

for (var i === 0; i < 21; i++)
{
    if(){

}
else if(){

}
else{

}
}

Then now when you operate your not suppose to use three equalmarks like @cadecodes did, but your suppose to use one equal mark to see if it equals that.

Hope this helped!


#6

@cadecodes
i copy your code and compare to mine

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

if (x % 3 === 0 && x % 5 === 0) {
    console.log("FizzBuzz");
}

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

}
else if( x % 3 ===0){
    console.log("Fizz");
{



else {
    console.log(x);
}
}

i really dont see any difference, but thats not running