Switch Statement(Advance JavaScript)
function moveCommand(direction) {
var whatHappens;
switch(direction) {
case "forward":
whatHappens = "you encounter a monster";
break;
case "back":
whatHappens = "you arrived home";
break;
case "right":
whatHappens = "you found a river";
break;
case "left":
whatHappens = "you run into a troll";
break;
default:
whatHappens = "Please enter a valid direction";
}
return whatHappens;
}
Source: 9:01 (149. Advanced Control Flow) >> Udemy
Comments
Post a Comment