Computer choice 2


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();


if (computerchoice<=0.33) {

computerChoice = "rock";

} else if (computerChoice<=0.66){

computerChoice ="paper";

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

Replace this line with your code.


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?"


var computerChoice = Math.random(3){
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.


this helped me out a lot thank you


Your most welcome. :slight_smile:


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