Recursive switch


#1

<PLEASE USE THIS TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<Below this line, add a link to the EXACT exercise that you are stuck at.>
Code your own Adventure 2

<Below this line, in what way does your code behave incorrectly? Include ALL error messages.>
How do I rerun the switch statement with a new user input? If the user chooses an option that is not allowed how do I ask again for the correct color?
thank you,

```

var user = prompt(“Pick a color”).toLowerCase();

switch(user) {
case ‘red’:
console.log(“why not”);
break;
case ‘black’:
console.log(“huh???”);
break;
case ‘blue’:
console.log(“ok, great choice”);
break;
default:
console.log(“choose a new color (red, black, blue”);
}

<do not remove the three backticks above>

#2

It would not be a recursion, just an endless loop. However, loops may not have been covered yet so this problem will need to wait for a solution until after you have covered the concepts in the upcoming units. Set this aside for the time, and return when you have completed the track.


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.