Javascript problem

Javascript problem
0

#1

Tell us what’s happening:

what’s the problem with the code?

Your code so far


function caseInSwitch(val) {
  var answer = "";
  // Only change code below this line
  switch (val) {
    case val === 1:
    return "alpha";
    break;
  
    case val === 2:
    return "beta";
    break;

    case val === 3:
    return "gamma";
    break;
  
    case val === 4:
    return "delta";
    break;

  }
  
  // Only change code above this line  
    


// Change this value to test
caseInSwitch(1);

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/selecting-from-many-options-with-switch-statements


#2

You don’t need to explicitly type val === 1, by typing case it’s already doing the val ===; all you need is to put the value. ex:

case 1:


#3

In addition to what @zapcannon99 mentioned, you have not followed the instructions of the challenge. The instructions say:

Write a switch statement which tests val and sets answer for the following conditions:
1 - “alpha”
2 - “beta”
3 - “gamma”
4 - “delta”

Where are you setting the value of answer variable and why did you delete the return statement below the line shown below:

  // Only change code above this line  

You must pay attention to all the details given in the instructions and code comments supplied by the challenge.