I am very new to all of this and I recently started learning JavaScript. To test my learning I made this simple script, Rock, paper, and scissors. It is something very similar to Codecademy project. The problem I am having is with the output, which comes out as 'undefined' and I can't figure out, what's giving this output, can someone please help?
const getUserChoice = userInput => {
userInput = userInput.toLowerCase();
if (userInput === 'rock') {
return 'Rock'
} else if (userInput === 'paper') {
return 'Paper' }
else if (userInput === 'scissors') {
return 'Scissors'}
else if (userInput === 'bomb') {
return 'Bomb'
} else {
return 'Please input a valid choice!'
}
}
const getComputerChoice = () => {
const numbers = (Math.floor(Math.random() * 3))
switch (numbers) {
case 0 : return "Rock";
break;
case 1 : return "Paper";
break;
case 2 : return "Scissors";
break;
}
}
const determineWinner = (userChoice, computerChoice) => {
if (userChoice === computerChoice) {
return 'It\'s a tie!!';
}
if (userChoice === 'rock') {
if (computerChoice === 'paper') {
return 'The Computer has won the game!!';
} else {
return 'Congratulation You have won the game!!';
}
}
if (userChoice === 'scissors') {
if (computerChoice === 'rock') {
return ('The Computer has won the game!!');
} else {
return ('Congratulations You have won the game!!');
}
}
if (userChoice === 'scissors') {
if (computerChoice === 'paper') {
return 'Cogratulations You have Won the game!!';
} else {
return 'The Computer has won the game!!';
}
}
if (userChoice === 'bomb') {
return 'Congratulation you Won!!'
}
};
const playGame = () => {
var userChoice = getUserChoice('rock')
var computerChoice = getComputerChoice()
console.log('You picked: ' + userChoice);
console.log('The computer picked: ' +computerChoice)
console.log(determineWinner(userChoice, computerChoice));
}
playGame()