Switch Statements

Tell us what’s happening:

what needs to be changed in my code to work?

Your code so far


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

   case 3:
  return "gamma";
  break;

  case 4:
  return "delta";
  break;
  
  // Only change code above this line  
  return answer;  
}

// Change this value to test
caseInSwitch(1);
caseInSwitch(2);
caseInSwitch(3);
caseInSwitch(4);

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.79 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/

You’re not assigning the value ‘alpha’, ‘delta’, etc to the ‘answer’ variable , you’re just returning the value ( which make the ‘break’ unreachable, but i guess that’s not your problem ^^ )

ya tried assigning values but still doesnt work

Show us what you tried.

function caseInSwitch(val) {
  var answer = "";
  // Only change code below this line
  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;  
}

// Change this value to test
caseInSwitch(1);
caseInSwitch(2);
caseInSwitch(3);
caseInSwitch(4);

You should review the example in the challenge, because you are not even using the switch statement in the code you just posted.

FYI - I’ve edited your post for readability. When you enter a code block into the forum, precede it with a line of three backticks and follow it with a line of three backticks to make easier to read. See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.

markdown_Forums

omg ! such a silly mistake I had made. sorry to post. Thanks for saving my night. It works now