I'm trying to create a basic Rock, Paper, Scissors game.
Because there are quite a bit of conditions for each turn, I wanted to use switch
instead of if
& else
.
My code is:
var computerChoice = Math.floor(Math.random() * 3)
var humanChoice = prompt('1 = Rock | 2 = Paper | 3 = Scissors')
console.log(humanChoice);
console.log(computerChoice);
switch (computerChoice, humanChoice) {
case 1 , 1:
confirm('ROCK VS ROCK its a draw!');
console.log(humanChoice);
console.log(computerChoice);
break;
case 1 , 2:
confirm('Paper win against rock! Human won!');
console.log(humanChoice);
console.log(computerChoice);
break;
case 1 , 3:
confirm('Rock win against scissors! Computer won!');
console.log(humanChoice);
console.log(computerChoice);
break;
case 2 , 1:
confirm('Paper win against rock! computer won!');
console.log(humanChoice);
console.log(computerChoice);
break;
case 2 , 2:
confirm('PAPER VS PAPER its a draw!!');
console.log(humanChoice);
console.log(computerChoice);
break;
case 2 , 3:
confirm('scissors win against paper! Human won!');
console.log(humanChoice);
console.log(computerChoice);
break;
case 3 , 1:
confirm('Rock win against scissors! Human won!');
console.log(humanChoice);
console.log(computerChoice);
break;
case 3 , 2:
confirm('scissors win against Paper! Computer won!');
console.log(humanChoice);
console.log(computerChoice);
break;
case 3 , 3:
confirm('SCISSORS VS SCISSORS its a draw!');
console.log(humanChoice);
console.log(computerChoice);
break;
default:
confirm("I don't remember telling you that " + humanChoice + " is an option.");
break;
};
The code actually jumps to the default, which is quite a bummer. What am I doing wrong? I guess it's the way I wrote the conditions in the cases, but even after searching Google, I couldn't make it work.