Weird error message


#1


https://www.codecademy.com/courses/spencer-sandbox/0/3?curriculum_id=506324b3a7dffd00020bf661#


Hello,

I am receiving a funny but weird error message in my code. It says, "Oops, try again. You printed Fizzbuzz when you should have printed Fizzbuzz.

I looked at another article in which they had the correct answer, but for some reason although both programs are the same, their program works and mine does not.

Please help A.S.A.P.

Thanks in advance!

P.S. The first piece of code is the one that I found elsewhere, and the second is the one that I made.


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

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

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

    else{    
        console.log(i);
    }
}



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


#2

@designrockstar15271
Why are you using 2 FOR-loops ????


#3

I said in there, the first one is the one that I found elsewhere. I was looking for help in finding out why the two were different.


#4

It seems your missing many semi-colons also spacing sometimes helps for readability when debugging esspecially


#5

nevermind i was mistaken


#6

try using nested if statements


#7

I tried the nested if-statements idea, and it worked! Thank you very much! I would have never thought of that myself.


#8

@designrockstar15271,
But the problem was you using

1st FOR loop

"FizzBuzz"

in the 2nd

"Fizzbuzz"

as was mentioned in the Oops-message
Oops, try again. You printed Fizzbuzz when you should have printed FizzBuzz.


#9

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