Computer choice 2


#1

my code keeps telling me computerchoice is undefined and I'm havin trouble figuring out what to do after following the instructions

var userChoice=prompt("do you choose rock, paper, scissors?");

var computerChoice=Math.random();

console.log(computerChoice);

if (computerchoice<=0.33) {

computerChoice = "rock";

} else if (computerChoice<=0.66){

computerChoice ="paper";

} else { (computerChoice >67)
computerChoice = "scissors";
}
console.log(computerChoice);


Replace this line with your code.


#2

You also need to put your if and else if statements inside computer choice's curly brackets.

Your finished code should look like this.

var userChoice = "Do you choose rock, paper or scissors?"

prompt(userChoice)

var computerChoice = Math.random(3){
    console.log(computerChoice){
}
if (computerChoice <= 0.33) {
    computerChoice = "rock";
} else if (computerChoice <= 0.66) {
    computerChoice = "paper";
} else {
    computerChoice = "scissors";
}
}

Study this code and look at the differences. If that helped please mark my reply as the solution.


#3

this helped me out a lot thank you


#4

Your most welcome. :slight_smile:


#5

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