Please help me with this code for rock paper game


#1

/*var userChoice = prompt("Do you choose 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(choice1,choice2){
if (choice1 === choice2)
return "The result is a tie";
};
compare(computerChoice,userChoice);

The error I get is below :

this is the link on which I am working :-
https://www.codecademy.com/courses/javascript-beginner-en-Bthev-mskY8/1/1?curriculum_id=506324b3a7dffd00020bf661#


#2

@siddy335

Look here:

Your if statement needs a curly bracket after defining your condition otherwise the };
at the end is closing nothing.


#3

if I write it like this
(var compare = function(choice1,choice2){
if (choice1 === choice2){
return "The result is a tie";
}};
compare(computerChoice,userChoice):wink:

Then still I am getting the same error :frowning:


#4

@siddy335

Here

No need of parentheses before declaring a variable!


#5

Okay please check is this correct ?

var userChoice = prompt("Do you choose 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(choice1,choice2){
if (choice1 === choice2){
return "The result is a tie";
}};
compare(userChoice,computerChoice);


#6

@siddy335
Free from error! I think what you've got to care about is whether it's respecting the instructions given in the exercise. Good luck! :grin:


#7

A post was split to a new topic: I tried creating my own R,P,S, but I think this code does not seem to be working in my browser


#8

LOL Thanks, I'll check it