4. Computer Choice: Part 2 - Help


#1

Can someone help me please.
When I try to submit my code I get an error and I don't know why.
So this is my code:

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

As output I get:

0.5512581041548401
TypeError: computerChoice is not a function

and that's the error:

Oops, try again. Your code doesn't look quite right. Check the Hint if you need help!


#2

I solved my problem.


#3

I cant figure it out!! :frowning:
var userChoice = prompt("Do you choose rock, paper or scisssors?");
var computerChoice = Math.random();
console.log(computerChoice);
{
if (0 < computerChoice < 0.33) {
computerChoice("rock");
}
else if(0.34 < computerChoice< 0.66) {
computerChoice("paper");
}
else {
computerChoice("scissors");
}


#4

if (0 < computerChoice < 0.33) {

This doesn't work in javaScript. 0 < computerChoice < 0.33 would just be splitted int

(0 (true/false) < 0.33 // as true has a value of 1 and false of 0
(1/0) < 0.33

which does pretty much the opposite of what it should do.
Also your supposed to add the assign the value to computerChoice not console.log it.