Help correct, please

Tell us what’s happening:

Your code so far


function caseInSwitch(val) {
var answer = "gamma";
// Only change code below this line
switch("answer") {
case  "alpha":
  console.log("alpha");
  break;
case "beta":
  console.log("beta");
  break;
   case "gamma":
  console.log("gamma");
  break;
   case  "delta":
  console.log( "delta");
  break;
}


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

caseInSwitch(1);

Your browser information:

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

Challenge: Selecting from Many Options with Switch Statements

Link to the challenge:

Hello there.

Do you have a question?

If so, please edit your post to include it in the Tell us what’s happening section.

The more information you give us, the more likely we are to be able to help.

2 Likes

i dont know how to solve this case statement

are you changing the value of answer as requested?

yes, to one. but then? are you seeing my code?

You need to post any changes to your code.

Tell us what’s happening:

Your code so far


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


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

caseInSwitch(1);

Your browser information:

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

Challenge: Selecting from Many Options with Switch Statements

Link to the challenge:

you are missing the closing parenthesis of the switch statement

but also, if you fix that, your function is always returning 1, you need to set the value of answer based on the value of val - if you change val you loose the input value

Hi @emilionovillo2,
Do not assign value for the answer at the beginning. you have to edit code between given lines. In this challenge, you have to check the value given as the parameter (val) and assign the appropriate answer according to that value. Therefore the variable that is being checked inside the switch statement must be val. According to the val, you have to assign the relevant value (alpha, beta…) as the answer.
So your switch statement should be like this

switch (val){
    case 1:
      answer = "alpha";
      break;
    case 2:
      answer = "beta";
      break;
    case 3:
      answer = "gamma";
      break;
    case 4:
      answer = "delta";
      break;    
  }