Introduction to Objects 3. And the good


#1

This seems to be working except for the number 15. "Fizz" is being printed to the console instead of "FizzBuzz". I'm not sure where I'm going wrong, any help would be greatly appreciated.

for(var 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);
}
};


#2

@flyingfox2015,
You should use the most specific condition

(i % 3 === 0 && i % 5 === 0)

as first condition-test.


#3

A post was split to a new topic: Introduction to Objects no. 3


#4

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