And the good


#1

var numbers = {
for(i = 0; i =< 20; i++){
if (i % 3 === 0){
console.log("Fizz");
}else if(i % 5 === 0){
console.log("Buzz");
}else if(i % 3 && i % 5){
console.log("FizzBuzz");
else{
console.log(i);
}
}
}
}
numbers(i);
Gives me an syntax error =
Dunno wheres that bad =?


#2

line 1 : u dont need variable, just begin the for loop,
line 2 : "<=" not "=<" , and the loop should begin from 1, i = 1
line 3,5,7 : u make computer confuse "ex : (i % 5 === 0)" better like this "((i % 5) === 0) ";
gud luck


#3
var numbers = {
  for(i = 0; i =< 20; i++){
    if (i % 3 === 0){
      console.log("Fizz");
    }else if(i % 5 === 0){
      console.log("Buzz");
    }else if(i % 3 && i % 5){
      console.log("FizzBuzz");
    else{
      console.log(i);
    }
  }
}
}
numbers(i);

On line 1, you don't need to create an object.

On line 2, =< should be <=. Your loop also runs 21 times instead of 20, so i should start off as 1. (as the person above me said)

Line 3 and 5 are fine, you don't need to surround them with brackets.

On line 7 you don't make an equation at all, there should be an answer to check, for example:

if(1 + 1 === 2 && 2 * 2 === 4) {
  //...
}

On line 9 you never close the else if statement, but you close it on line 14 (which is where it shouldn't be closed)


#4

@mrbumbum

Line 1 - You can just start off with a for loop.
Line 2 - The instructions stated, numbers from 1 - 20. You're starting from 0. Also less than or equal to is <= not the other way around.
Line 7 - Your syntax is incorrect. Your code should look like else if(i % 3 === 0 && i % 5 === 0)

Code logic - Lets go over the logic of your code.
Step 1 - (i % 3 === 0) // this means that the numbers 3, 6, 9, 12, 15, 18 will all console.log("Fizz")

Step 2 - (i % 5 === 0) // this means that the numbers 5, 10, 15, 20 will all console.log("Buzz")

Step 3 - (i % 3 === 0 && i % 5 === 0) // this means any number divisible by both 3 and 5 should console.log ("FizzBuzz") - the only number that is true to this is the number 15. If you fix your code and run it the number 15 will not show "FizzBuzz" it will show "Fizz" because your first logic of i % 3 === 0 was true and it console.logged "Fizz"

Change the logic of your code to start from step 3 first, than step 1 and lastly step 2. See my code below to go over the logic and also the syntax of your code.

Also try working on indenting better, it will help with debugging and other people reading your code!


#5

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

This worked for me!


..and the good Browser keeps crashing
#6

Thanks my niggus... should have mentioned that i got it fixed... altho I still learned alot from your replies. ^.^


#7

I do ident them but when i copy and paste it it just randomly removes it... pushes each code forwards on each line.