Introduction to Objects I ...And the good!


#1

Im getting a little behind in Javascript, and i think its difficult right now, so i was hoping anyone could help me soon? So i was trying to put this code together, as simple as possible.

Objective: Print out the numbers from 1 - 20.
The rules:
For numbers divisible by 3, print out "Fizz".
For numbers divisible by 5, print out "Buzz".
For numbers divisible by both 3 and 5, print out "FizzBuzz" in the console.
Otherwise, just print out the number.

Code:

for (var i = 0; i < 21; i++) {
if (i / 3 === true) {
console.log("Fizz")
} else if (i / 5 === true) {
console.log("Buzz")
} if (i / 8 === true) {
console.log("FizzBuzz")
} else {
console.log(i);
}
}


#2

HI you should use modulo % instead of / and you should put after your === the number 0 to check that the remain of the division is equal to 0 like that

if (i % 3 === 0) {

}

And read well the rules
For numbers divisible by 3, print out "Fizz".
For numbers divisible by 5, print out "Buzz".
For numbers divisible by both 3 and 5, print out "FizzBuzz" in the console.
Otherwise, just print out the number.
There isn't a number 8


#3

Oh, like that. Thanks for the help bro :smiley: