Stuck - Javascript Math.random


#1

Im supposed declare a variable called computerChoice and make it equal to Math.random(). The print out computerChoice so as to see how Math.random() works.

This was my first trial:
var userChoice = prompt("Do you choose rock, paper or scissors?");
var computerChoice = Math.random() {
console.log(computerChoice);
};

Then after visiting the Q&A forum I came up with this:
var 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 = "Scissors";
};
console.log(computerChoice);
};

But I'm still stuck,, please anyone, help me figure out what I'm doing wrong.


#2

you have set it up like its a function it should just be on two seperate lines,

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

#3

Tried that, it finally works!! Thanks alot @bandit


#4

You're welcome. :slight_smile:


#5