I'm stuck, help with first steps, please



I'm trying and can't understand. Now I'm trying do "Computer Choice: Part 1" and I,ve got this:

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

And don't know what's next? I saw in other posts, people made "if" strings, but I cant'understand why and what should I do to go to the next steps?

The instruction says:"Under your previous code, declare a variable called computerChoice and make it equal to Math.random().
Print out computerChoice so you can see how Math.random() works. This step isn't needed for the game - just useful for learning!"

Someone can explain simply?

Replace this line with your code.


At this step there is no need to do any if strings. I think what you are missing here is the third line of code, which should log to the console. Simply add a third line of code:


I hope this helps :slight_smile:


Yay, it's helps. :slight_smile:

But can you explain why computer showed: 0.06029167698799509 number? Do I understand right that " Math.random() " make this number randomly?


Math.random() will create a random number between 0 and 1.

You will learn how to turn that into larger numbers in a later lesson.

To give you a headstart, it is done like this:


would give you a random number between 0 and 10

Math.floor, gives you the whole number, rounded down.

Math.random, as you know, generates a random number.

*11 would multiply the random number by whatever number you put after the *

You will never generate the number 11 because it's rounded down, so always go 1 number higher than the maximum number you want to generate.


Thanks a lot for your explanation. Now I understand. :slight_smile: Have a nice day.


var userChoice = prompt( "Do you choose rock, paper or scissors?");
var computerChoice = Math.random();
if(computerChoice <= 0.33)
computerChoice = "rock";
else if(computerChoice > 0.34 && computerChoice < 0.66)
computerChoice = "paper";
computerChoice = "scissors";


/*The correct code.
Pick it up and think about it)*/
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);

function compare(choice1,choice2){
if(choice1 === choice2){
return "The result is a tie!"}
else if (choice1 === "rock"&&choic2 === "scissors"){return "rock wins"}
else if (choice1 === "paper"&&choice2 === "rock"){return "paper wins"}
else{return "scissors wins"}