How is an unrecoverable syntax error fixed?

How is an unrecoverable syntax error fixed?
0

#1

Continuing the discussion from freeCodeCamp Challenge Guide: Replacing If Else Chains with Switch:

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;
    default:
              answer = "Ate Nine";}
  

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

The above is my code. Below is the answer from the camper bot:

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;

}

My own answer seems exactly the same as the above, at least as far as I can tell.


#2

What is the syntax error you are getting?


#3

unrecoverable syntax error 76% at the return answer part of the code…


#4

I have no idea what you mean.


#5

I think I’m making a syntax error. Are you able to spot it?


#6

What makes you think you are getting a syntax error? Are you seeing an error in the console?
If not, what tests are failing?


#7

I’ll take a screenshot, just hold on.


#8


#9

Look at your opening and closing curly braces ({ and }) to see if they match up.


#10

ifelse2switch update 2

now I’m getting Syntaxerror: Illegal return statement

any suggestions?


#11

Your return statement is not inside a function.


#12

I’m not sure what I still need to check off on the check boxes. I don’t know what I’m doing wrong. I’ve made the changes about including return inside the function.


#13

Because you have a default that returns "Ate Nine", the last two tests are failing. chainToSwitch("John") and chainToSwitch(156) both return "Ate Nine".


#14

how do I address “John” in the case statement format. Can you give an example?


#15

Why do you have "Ate Nine" in a default case? Did the instructions say that it should be the default?


#16

Yes
See the picture.
confusedinstructions()


#17

That doesn’t say anything about always returning "Ate Nine" for all values that are not "bob", 42, 1, or 99.


#18

At John and 156 the program is still returning error. As far as I can tell, I cant see a syntax error.

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;
    case "John":
      "";
    break;
    case 156:
      "";
  
  // Only change code above this line  
  return answer;  
}


#19


#20

""; is not a valid line of code.