Rock, paper, scissors - I need help in an additional part of code


#1

https://www.codecademy.com/courses/javascript-beginner-en-Bthev-mskY8/1/5?curriculum_id=506324b3a7dffd00020bf661

I get this Error massage when I run the code - SyntaxError: Invalid or unexpected token
Please help me find what I did wrong!

var userChoice = prompt("Do you choose rock, paper or scissors?");
//userChoice is not right
if (userChoice==="rock")
{
   console.log("Thanks, let's continue playing!") 
}
else if (userChoice==="paper")
{
    console.log("Thanks, let's continue playing!") 
}
else if (userChoice==="scissors")
{
   console.log("Thanks, let's continue playing!)  
}
else
{
  var userChoice = prompt("Please choose from the options: rock, paper or scissors?")  
}

var computerChoice = Math.random();
if (computerChoice < 0.34) {
	computerChoice = "rock";
} else if(computerChoice <= 0.67) {
	computerChoice = "paper";
} else {
	computerChoice = "scissors";
} console.log("Computer: " + computerChoice);

var compare = function(userChoice,computerChoice)
{
//tie:
  if (userChoice===computerChoice)
  {
      return "The result is a tie!"
  }
  //user picked rock
  else if (userChoice==="rock")
  {
     if(computerChoice==="scissors")
     {
        return "rock wins" 
     }
     else
     {
        return "paper wins" 
     }
  }
  //user picked paper
  else if (userChoice==="paper")
  {
     if (computerChoice==="rock")
     {
        return "paper wins" 
     }
     else
     {
        return "scissors wins"
     }
  }
  //user picked scissors
  else if (userChoice==="scissors")
  {
    if (computerChoice==="rock")
    {
        return "rock wins"
    }
    else
    {
        return "scissors wins"
    }
  }
};
console.log(compare(userChoice,computerChoice))

#2

Missing quation mark in console.log after the
}
else if (userChoice==="scissors")
{

peter


#3

This is my code:
var compare = function (userChoice, computerChoice)
{
if (userChoice === computerChoice) {
return "The result is a tie!";
}
else if (userChoice === "rock")
{
if (computerChoice === "scissors")
{
return "rock wins!";
}
else
{
return "paper wins!";
}
}
else if (userChoice === "paper")
{
if (computerChoice === "rock")
{
return "paper wins!"
}
else
{
return "scissors wins!"
}
}
else if (userChoice === "scissors")
{
if (computerChoice === "rock")
{
return "rock wins!"
}
else
{
return "paper wins!"
}
}
};

it works but I keep getting this error message saying
"Oops, try again. Your code returned 'paper wins!' instead of 'undefined' when the inputs are scissors and paper"
please help me


#4

you need to close the code with - console.log(compare(userChoice,computerChoice))
so it'll know what to do with the data you "returned"


#5

Who wins when the choices are scissors and paper?


#6

it just says the try again error code


#7

You have to become familiar with how this game is played.

Paper covers rock. Rock breaks scissors.

What does scissors defeat?


#8

var userChoice = prompt("Do you choose rock, paper or scissors?");
console.log("Playa: " + userChoice);
var computerChoice = Math.random();
console.log(computerChoice);

if(computerChoice < 0.34) {
computerChoice = "Rock";
} else if(computerChoice <= 0.67) {
computerChoice = "Paper";
} else {
computerChoice = "Scissors";
}
console.log("AccordingToTheComputer: " + computerChoice);

This is my code, everything is fine and prints out to the console, but for some reason there's a bug where it pops up with the error message: "Oops, try again. Did you set var computerChoice = Math.random() ? The capital 'M' in 'Math' is important!"

Anyone spot anything i don't?

Thanks


#9

Dudes sorry to waste your time jus figured out theres a difference between '=' and '==='
caught a newb in the newd :L


#10

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.