Switch statement not running

i have been trying to run this code while going through JS curriculum

function caseInSwitch(val) {
  let answer = "";
  // Only change code below this line
switch(val){
  case "1":
  answer = "alpha";
  break;
  case "2":
  answer = "beta";
  break;
  case "3":
  answer = "gamma";
  break;
  case "4":
  answer = "delta";
  break;
}


  // Only change code above this line
  return answer;
}

caseInSwitch(1);

however its not running
a little help would be appreciated.
thanks.

Edit: I see it. I can never get the posts to scroll down. It can be sort of confusing with the example they give for a switch because they use a string, and the test wants you to use a number. Better described in the post below.

I have edited your post to include the challenge link.
When you ask for help on the forum please always including the link so we know what lesson you are on.

Thanks!

Your issue is that you are using strings here instead of numbers

Strings are not the same data type as numbers.
The test are looking for numbers.

When I change that then it passes

It can be sort of confusing with the example they give for a switch because they use a string, and the test wants you to use a number.

Right, but they never said it was for strings specifically. The text just talks about “values”. switch will work with any primitive type. Technically it will work with reference types (I assume) but it would compare the references, not the values, so that might not work the way you expect, at first glance.

A good habit for any developer is to google things. I would go to MDN and check the documentation for switch. Get in the habit of checking the docs.

@jwilkins.oboe thanks for the reply. I got confused from the challenge because strings have been used there. I got the impression that all values in the case statement are to be quoted.
thanks.

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