Intro to Objects 1 # 3 ...and the good


#1



Intro To Objects 1, #3 ...And the good.


Oops try again. You printed Fizzbuzz when you should have printed Fizzbuzz.


Here is what my code looks like.. 

for (var i = 1 ; i<= 20; 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);
    }
}

What went wrong here?


#2

I think you (incorrectly) copied the error message by hand instead of using your OS's clipboard feature. I don't think that's the error message you got.

So what does the real error message say that what you wrote here doesn't?


#3

It really says "Oops, try again. You printed Fizzbuzz when you should have printed FizzBuzz."


#4

And are those the same?


#5

They are not. And I will never be the same again either...:pensive:


#6

Forever onwards looking for those little details I hope :P


#7

Thank you very much!


#8

Hey dude, I had the same problem with the same error message for a while until i finally figured it out. Your code looks identical to mine, except for the first line. Here is mine: for(i = 1; i < 21; i++) Hope that helps! I would try to explain it, but I'm not really sure why yours doesn't work. Its syntax looks fine.


#9

I think the problem comes from for (var i = 1 ; i<= 20; i++) . You shouldn't put "var". At least for me this is the way it works: for ( i = 1; i <= 20; i++) {...

You must have mixed the format of the for loop and the for/in loop...

Yet I'm not an expert, I might also be mistaken.


#10

Replace Fizzbuss to FizzBuzz


#11

I kept it to "i<21" and it worked for me


#12

YUP this code is fine is the spelling in your console.log lol just a typo


#13

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);
}

};

at last that semicolon i think so..