Help


#1

why : SyntaxError: Unexpected token else


var num = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20];
for (var i = 0; num.length<21; i++)
{
    if (num[i]%3 === 0)
    {
        if (num[i]%5 === 0)
        {
            console.log("FizzBuzz");
            i++;
        }
        else
        {
            console.log("Fizz");
            i++;
        };
    };
    else if (num[i]%5 === 0)
    {
      if (num[i]%3 === 0)
        {
            console.log("FizzBuzz");
            i++;
        }
        else
        {
            console.log("Buzz");
            i++;
        }
    }
    else
    {
        console.log(num[i]);
        i++;
    }
};


#2

Hi the error come from this part

if (num[i]%3 === 0)
    {
        if (num[i]%5 === 0)
        {
            console.log("FizzBuzz");
            i++;
        }
        else
        {
            console.log("Fizz");
            i++;
        };
    }; <-- remove the ;

then here

for (var i = 0; num.length<21; i++)

this part

num.length<21

why not change it to

i < num.length

HOpe that could help you


#3

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