Why does this code not work!


var e
var answer = prompt("What is your favourite single digit number","Write a number from 0 to 9");
var e = (isNaN(answer))
if (e) {
   switch(answer) {
 case '0':
     console.log("single digit, but not sure if number")
     default ' ':
        console.log("I love this number aswell!") 
    console.log("SIKE, THATS THE WRONG NUMBER! (or not one)")

why dont this work?


remove ' ' from

default ' ' //here


default can't have a condition:

   // do something

since default is everything else, you can't specify a case.

also, there is a problem here:

var e = (isNaN(answer))

if answer is a number, the condition evaluates to false (number is not a number, well, it is a number, so it is false), otherwise true. You should reverse it (you can use a !.


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