Replacing If Else Chains with Switch - Unidentifiable Error

Replacing If Else Chains with Switch - Unidentifiable Error
0.0 0

#1

What’s wrong with my code? I checked it against the answer here, and it’s exactly the same. It even returns all the right values in the tests, but it’s giving me errors for having “if” “else” and not enough “break” statements, even though the code doesn’t violate any of these rules. Please help.

Edit: The answers provided on the forum are also flagged with all kinds of issues when copy-pasted, unable to complete this challenge and move on.

function chainToSwitch(val) {
  var answer = "";
  // Only change code below this line
  
  switch(val) {
    case "bob": 
      answer= "Marley"; 
      break;
    case 42: 
      answer= "The Answer"; 
      break;
    case 1: 
      answer= "There is no #1"; 
      break;
    case 99: 
      answer= "Missed me by this much!"; 
      break;
    case 7: 
      answer "Ate Nine";
      break;
      
  }
  
  // Only change code above this line  
  return answer;  
}

// Change this value to test
chainToSwitch(99);

Using Chrome.

Link to the challenge:


#2

answer “Ate Nine”;

Also, I don’t know when these “ ” were added, but make sure you’re using ' ' or " ", particularly when copying and pasting.


#3

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.

As @bnoden highlighted, make sure you are assigning a value to answer for each case.


#4

You forgot to put a equal (=) sign in the " answer “Ate Nine”. Also try to make the chainToSwitch(99); to chainToSwitch(7);