3. ...and the good!


#1

Hello , exercise is here: https://www.codecademy.com/courses/spencer-sandbox/0/3?curriculum_id=506324b3a7dffd00020bf661#

My code is here:
for (i=1; i<21;i++){
if(i%3==0){
return "Fizz";
}
else if(i%5==0){
return "Buzz";
}
else if(i%3==0 && i%5==0){
return"FizzBuzz";
}
otherwise{
console.log (i);
}

I got error:
SyntaxError: Illegal return statement

but I have no idea what is wrong
Cheers


#2

The instructions ask you to print fizz/buzz, not return them.


#3

First of all, note what @tekkie1618 said. Also, you should be using an else to end and not otherwise.


#4

Now I got:
Oops, try again. You printed Fizz when you should have printed FizzBuzz

code:
for (i=1; i<21;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);
}

}


#5

I was waiting for you to do this.

Follow this order and its conditions.

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

[There is a test script behind every exercise.]


#6

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