Any help :(


#1

for (var num=0 ; num<21 ;num++){

switch (num){
case div3 :
if (num %3===0){
console.log("fizz");
break;

        case div5 :
            if (num %5===0){
                console.log("buzz");
                break;

            case both:
                if (num %3===0 && num %5===0){
                    console.log ("FizzBuzz");
                    break;

                    default:
                    console.log(num);
                }
            }
    }

}
//what is going wrong here ? ... the only thing that ive made that i prefare tp use switch and case methode instead of if and else if :confused:


#2

You need to end your if statements in their respective cases. I'm fairly certain that you can put a break inside of an if statement, as long as it also breaks after the if statement, or in an else. (After it hits the first "break" it ends the 'case' and reverts back to where it was in the code, so you don't need to worry about the code being damaged by multiple breaks as long as you have them where they do not interfere with your code.)

It's best practice to have only one break per case, so I would simply end the if statement and then have it break so that is won't error if the 'if' statement is false.


#3

You have to make the condition for FizzBuzz first, then Fizz and Buzz. And case div5 and case both are unnecessary. It should look like this:
for (var num = 0; num < 21; num++) {
switch(num){
case (I can't remember the case things...):
if (num % 3 === 0 || num % 5 === 0) {
console.log ("FizzBuzz");
} else if (num % 3 === 0) {
console.log ("Fizz");
} else if (num % 3 === 0) {
console.log ("Buzz");
} else {
console.log (num);
}
break;


#4

At least, I think this is somewhere close to right...