I can't get it any better


#1



https://www.codecademy.com/en/courses/spencer-sandbox/0/3

I've been stuck for three days. I don't know what could possibly be wrong with this. (Getting "unexpected token else")


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


#2

Your if statement's when closing is after } not add a ;

also you have a few blank and open if/else statements

remember the syntax:

if(condition){
//something
}
else {
//somethingelse
}

At the end of each console.log(); add semi colon


#3

I don't understand -- how are they open? The semi-colons don't help


#4

Have a look at the above two ^
Correct your syntax, add the semi colons to console.log, remove semi colons from after } and then paste in your updated code


#5

Those are open? The instructions are on the next line. Not trying to be difficult here, I genuinely don't understand.

This doesn't work:

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

#6

Just saw I left the semicolon off the last console.log. Fixed that, still doesn't work.


#7

Have a look at this ^ you have no closing bracket and no console.log also your condition isn't correct.

This else if you have a bracket in between..

i suggest resetting the lesson reading the instructions and start again.

Remember for this instruction :arrow_right: For numbers divisible by both 3 and 5, print out "FizzBuzz" in the console. you use && to check the two sums


#8

It was supposed to be a nested conditional? That's what the instructions said. So I was trying to make the body of the if a second conditional and the same with the else. I saw on here some people are using && to check for FizzBuzz first, but that's not a nested conditional.


#9

Missing brace before second else:

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

#10

The nested conditional approach is fairly common, though not everyone intuits it. There are many ways to perform this function. Take for instance if - else if - else...

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.toString());
    }
}

Or we can use a switch statement...

for (var i = 0; i < 21; i++) {
    switch (true) {
    case i % 15 === 0:  console.log("FizzBuzz"); break;
    case i % 5 === 0:  console.log("Buzz"); break;
    case i % 3 === 0:  console.log("Fizz"); break;
    default: console.log(i.toString());
    }
}

#11

Duh of course. That fixed it, thanks


#12

So long as we don't let the little stuff take our eye off the big picture. It's dust, and it exists everywhere. We will always make mistakes. It's up to us to know the areas of weakness and their cures, and how to check them for validity.