This is an ongoing school project that I would like to improve. The point is to make the code as efficient (or short) as possible. I would like to reduce it by finding an al
Switch statements goes like that. Try to look at the e.g i gave you and try to understand the flow of the code.
Best way to learn is with your hands! Random switch eg:
switch(expression) {
case x:
code block
break; // after every statement e.g: (console.log) you need to use
"break"
case y:
code block
break;
default:
code block
}
Your code:
switch (weapon) {
case chosenOne:
return console.log(alert("It's a tie! Try again to win!"));
break;
case "Rock":
case "Paper":
alert("You lost! Paper beats the rock.");
break;
case "Paper":
case "Scissors":
console.log(alert("You lost! The scissors cut the paper."))
break;
case "Scissors":
case "Rock":
console.log(alert("You lost! The rock beats the scissors."))
break;
case "Scissors":
case "Paper" :
alert("You won! Scissors cut the paper.");
break;
case "Paper":
case "Rock":
console.log(alert("You won! Paper beats the rock."))
break;
case "Rock":
case "Scissors":
alert("You won! The rock beats the scissors.");
default:
return "somthing went wrong"
break;