I have done what i have suggested....now help me again to get rid out of these

Tell us what’s happening:

Your code so far



  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;

   
  7answer = "Ate Nine";
  break;

  }


  return answer;

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

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

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:61.0) Gecko/20100101 Firefox/61.0.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/replacing-if-else-chains-with-switch/

Remove the brackets from case expressions if that expression is a number.

You seem to be returning the answer twice.
In the last case, with the 7 it doesn’t seem quite correct.

Otherwise I believe it looks good :slight_smile:

Correct Code:

//code for last case

default:
answer = "Ate Nine";
//Only do this much change in the code and check the result

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;

default:
answer = “Ate Nine”;
break;

can u plz find the mistake

// Remove break statement with default case
//Rest should be fine

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;

default:
answer = “Ate Nine”;

}

return answer;

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

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

it seems nothing … plz kindly help me get rid out of these

You don’t want to have a default case, only do what I’ve told you in the beginning (remove brackets from case expressions that are numbers).

You obviously also want to fix the last case in your original post

7answer = "Ate Nine";
  break;

Nothing more than that.

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;

7answer = “Ate Nine”;
break;

}

return answer;

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

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

You forgot this fix this

Not to be discouraging, but you’ll really not learn a lot if you only imitate our answers and don’t try to figure out why the stuff’s not working the way it’s supposed to.