can anyone explain why my switch statement is printing out default?
can anyone explain why my switch statement is printing out default?
var x = 30;
switch(x) {
case x % 3 ===0 && x % 5 ===0:
(result = "fizzbuzz");
break;
case x % 3 ===0:
(result = "fizz");
break;
case x % 5 ===0:
(result = "buzz");
break;
default:
console.log("couldn't find the answer")
}
var x = 30;
switch(x) {
case x % 3 ===0 && x % 5 ===0:
(result = "fizzbuzz");
break;
case x % 3 ===0:
(result = "fizz");
break;
case x % 5 ===0:
(result = "buzz");
break;
default:
console.log("couldn't find the answer")
}
No any search results
You already invited:
2 Answers
TimDaub
Upvotes from:
Denis
Upvotes from:
switch (x) {
case true:
(result = "fizzbuzz"); break;
}
and since x equals 30, and not equals to true therefore the condition doesn't match and passes by until default is hit (since x%3===0 and x%5===0 conditions also yield true).