3. Computer Choice: Part 1


#1

userChoice = prompt("Do you choose rock, paper or scissors?");

var computerChoice = Math.random();

if (computerChoice <= 0.33) {
computerChoice = "rock";
} else if (computerChoice <= 0.66) {
computerChoice = "paper";
} else {
computerChoice <= 1;
computerChoice = "scissors";
}
console.log("Computer:" + " " + computerChoice);

I get this error: Oops, try again. Did you set var computerChoice = Math.random() ? The capital 'M' in 'Math' is important!


#2

You're ahead of the game. In this exercise you should only pick a random number and console.log it. As you've already converted it to a string, the test function gets confused as a number is expected and assumes that you didn't use Math.random correctly.

PS: You don't need this line

computerChoice <= 1;


#3

Thank you but i still get the same error


#4

Have you reduced your code to

Spoiler Alert

In case anyone else reads this

userChoice = prompt("Do you choose rock, paper or scissors?");

var computerChoice = Math.random(); 
console.log(computerChoice);


#5

Thank you so much!!!! It works :smiley:


#6

i do this and he tells me that prompt is not a function


#7

Have you tried to refresh the page?


#8

ah i figured it out... it was my bad because i declared userChoice as var... :slight_smile: thank you for your help :relaxed: