I tried to do this exercice on my own without following the guidelines. Please comment and tell me what you think about it. If you want to do the same exercice do not hesitate to add your code.
Thank you !
console.log('hi');
//get user choice
const userChoice = 'paper';
console.log(`User choice is ${userChoice} `)
//get computer choice
let computerChoice = Math.floor((Math.random()) * 3);
console.log(computerChoice);
switch (computerChoice) {
case 0: computerChoice = 'rock';
break;
case 1: computerChoice = "scissors";
break;
case 2: computerChoice = "paper";
break;
default: console.log('this is not a valid move');
}
console.log(`Computer choice is ${computerChoice}`)
//compare the two choices and determine a winner
const game = (userChoice, computerChoice) => {
if (userChoice === 'rock' && computerChoice === 'scissors') { console.log(`User chose ${userChoice} and computer chose ${computerChoice}, user win`); }
else if (userChoice === 'rock' && computerChoice === 'paper') {
console.log(`User chose ${userChoice} and computer chose ${computerChoice}, user loose`)
}
else if (userChoice === 'paper' && computerChoice === 'rock') {
console.log(`User chose ${userChoice} and computer chose ${computerChoice}, user wins`)
}
else if (userChoice === 'paper' && computerChoice === 'scissors') {
console.log(`User chose ${userChoice} and computer chose ${computerChoice}, user wins`)
}
else { console.log('User and computer chose the same, match nul'); }
}
game(userChoice, computerChoice);