Rock paper scissors


#1

why does mine keep comming up with "Oops, try again. Did you set var computerChoice = Math.random() ? The capital 'M' in 'Math' is important!" i diddnt even put in a Math.random() and when i did the same result came up please help


#2

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";
}

var compare = function(choice1, choice2) {
if(choice1 === choice2) {
return "The result is a tie!";
}
if(choice1 === "rock") {
if(choice2 === "scissors") {
return "rock wins";
} else {
return "paper wins";
}
}
if(choice1 === "paper") {
if(choice2 === "rock") {
return "paper wins";
} else {
if(choice2 === "scissors") {
return "scissors wins";
}
}
if(choice1 === "scissors") {
if(choice2 === "rock") {
return "rock wins";
} else {
if(choice2 === "paper") {
return "scissors wins";
}
}
}
}
};
console.log("User Choice: " + userChoice);
console.log("Computer Choice: " + computerChoice);
compare(userChoice, computerChoice);


#3

you have far too much code in it, this if/else if and else:

if (computerChoice < 0.34) {
    computerChoice = "rock";
} else if(computerChoice <= 0.67) {
    computerChoice = "paper";
} else {
    computerChoice = "scissors";
}

will overwrite the random number in computerChoice, giving you the error message


#4

var userChoice = prompt("Do you choose rock, paper or scissors?");
if (computerChoice < 0.34) {
computerChoice = "rock";
} else if(computerChoice <= 0.67) {
computerChoice = "paper";
} else {
computerChoice = "scissors";
}
i added this and it still comes up with the Math.random error message


#5

i also put this and the same error came up

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";
}


#6

you are still overwriting the random number stored in computerChoice with your if/else if/else block.

So you want to generate a random number:

var computerChoice = Math.random();

and then don't overwrite it if your if/else if/else block, remove it


#7

can i get an example of how much i need to wright as i dont know how much is too much


#8

you just need this:

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

and you then still need to add a console.log statement, to print out computerChoice


#9

my computer must just not work i have no clue why this doesnt work

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";
}


#10

ive got it cheers palito