Help me with the code.I keep getting You threw: rock The computer threw:undefined undefined undefined


#1

const getUserChoice =function(userInput){
userInput=userInput.toLowerCase();
if( userInput === ‘rock’ || userInput===‘paper’ || userInput=== ‘scissors’ ){
return userInput;
}else{
return ‘Error’;
}

}
let randomNumber=’’;
const getComputerChoice=() =>{
randomNumber= Math.random(Math.floor()*3);
switch(randomNumber){
case 0:
return ‘rock’;
case 1:
return ‘paper’;
case 2:
return ‘scissors’;
}

}
const determineWinner =function(userChoice, computerChoice){
if(userChoice===computerChoice){
return ‘The game is a tie’;
}
if (userChoice===‘rock’){
if(computerChoice===‘paper’){
return ‘computer wins’;
}else{
return ‘user wins’;
}
}
if(userChoice===‘rock’){
if(computerChoice===‘scissors’){
return ‘user wins’;
}else{
return ‘computer wins’;
}
}
if(userChoice===‘paper’){
if(computerChoice===‘scissors’){
return ‘computer wins’;
}else{
return ‘user wins’;
}
}
}

     const playGame=function(){

const userChoice =getUserChoice(‘rock’);
const computerChoice=getComputerChoice();
console.log('You threw: ’ + userChoice);
console.log(‘The computer threw:’ + computerChoice);
console.log(determineWinner(computerChoice,userChoice));
}
console.log(playGame());


#2

Math.random() does not take any parameters, It returns a value between 0 and 1.

Writing it as follows will give the expected result.
First you get a random number between 0 and 1, then multiply it by the max you want (in this case 3). then you want to floor this value to get your answer, 0, 1 or 2.
Math.floor(Math.random() * 3);