Rock, Paper, or Scissors


#1

function getUserChoice() {
var userInput = prompt('Please choose Paper Scissors or Rock');
}
if (userInput === 'scissors' || 'paper' || 'rock' ){
return userInput;
}
else {
console.log('Error!');
}
};
userInput = userInput.toLowerCase();

function getComputerChoice(){
Math.floor(Math.random() * 3);
}
switch(randomNumber){
case 0:
return 'rock';
case 1:
return 'scissors';
case 2:
return 'paper'
}
};
function determineWinner(userChoice, computerChoice){
if(userChoice === computerChoice){
return 'the game was a tie!';
}
if (userChoice === 'scissors') {
if computerChoice === 'paper'{
return 'The user won!';
} else {
return 'computer won!';
}
}
if (userChoice === 'paper') {
if computerChoice === 'rock'{
return 'user won!'}
else{
return 'computer won!';
}
}
if (userChoice === 'rock') {
if computerChoice === 'scissors'{
return 'user won';
} else { 'computer won';
}
}
function playGame(){
var userChoice = getUserChoice();
var computerChoice = getComputerChoice();
console.log('You threw' + ComputerChoice);
console.log('The computer threw' + userChoice);
console.log(determineWinner(userChoice, computerChoice));
}
playGame();

what is wrong with my code?


#2

First problem: Your brackets. Your getUserChoice() function only gets a prompt, because you've placed an extra bracket right below your userInput declaration. Same with getComputerChoice().
Second Problem. Your if statements for computerChoice don't have parentheses around them. Change statements like this: if computerChoice === 'scissors'{//Code} to statements like: if (computerChoice === 'scissors'){//Code}
That should be what's causing the trouble in your code.


#3

Thank you, I added parentheses and this part is fixed. However I can't delete extra bracket because then I see that tiny red indicator which says that I'm missing bracket. I also thought that one closing bracket is extra, but when I erase it computer doesn't like it either.
could you re-write this whole opening piece?: function getUserChoice() {
var userInput = prompt('Please choose Paper Scissors or Rock');
}
if (userInput === 'scissors' || 'paper' || 'rock' ){
return userInput;
}
else {
console.log('Error!');

};
userInput = userInput.toLowerCase();

function getComputerChoice(){
Math.floor(Math.random() * 3);
}
switch(randomNumber){
case 0:
return 'rock';
case 1:
return 'scissors';
case 2:
return 'paper'

};


#4

Oh! Your problem is:
On line 3 you have an extra bracket:

var userInput = prompt("Blahblah")
} //<--- This ends the function early, so delete it

And once that's out of the way, at your userInput.toLowerCase declaration, there's no bracket to end your function:

userInput = userInput.toLowerCase()
//Missing } here.

Second to last thing is that you end your getComputerChoice function early:

Math.floor(Math.random() * 3)
} //<--- Unnecessary bracket, as we want the function to continue.

And the final thing is that there's no end bracket below your switch statement at the end to finish your getComputerChoice function:

return 'paper'

};
//Missing } here.

After that, your code should work.