Computer Choice: Part 1


#1

Here is my code.

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

said to me.
Oops, try again. Did you set var computerChoice = Math.random() ? The capital 'M' in 'Math' is important!

What's wrong?
Please give me advise.


#2

the if/else if/else clause will overwrite the random number in computerChoice, remove it, or make it into a comment

the exercise validates there is a random number in computerChoice


#3

stetim94.
Thank you for your advise.
but I don't get it.
please teach me specific code.


#4

That is the problem, there is too much code in your case

look here:

console.log("Computer " + computerChoice);

what does it output? it should output a random number, it doesn't, why not? because you added more code then asked for.


#5

Thank you.
but I got same alert message.


#6

can you show me an updated version of your code?

just log computerChoice to the console, without any additional content (like a string)


#7

Thank you.
This is my code.

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";
}


#8

1.) If computerChoice is between 0 and 0.33, make computerChoice equal to "rock".
2.) If computerChoice is between 0.34 and 0.66, make computerChoice equal to "paper".
First, off just want to point out this is Computer Choice Part 2. If you are on Computer Choice Part 1 with this code we go other problems. Second, right here:

you need 0.33 not 0.34 as you can see by the instructions in 2.)
I copied your code into my lesson and that was the only change that you needed to make from the current code you have given us here


#9

Thank for your help.
To remove,"if/else"text.
I got through to next lesson.
here is my code.

var userChoice = prompt("Do you choose Rock,Paper or Scissors?");
var computerChoice = Math.random();
console.log(computerChoice);

Thanks.stetim94 and bibleman13 !!


#10