4 ComputerCoice Part: 2 (Can somone help with this problem?


Can somone help with this problem .

var userChoice = prompt("rock");
var computerChoice = Math.random();
if (computerChoice <= 0.33) {
return "rock"
} else if (computerChoice <= 0.66) {
return "paper"
} else {
if (computerChoice <= 1.0)
return "scissors"


You don't need this one:

if (computerChoice <= 1.0)

because Math.random() already makes sure that this is correct. Also your not inside of a function so using return is probably the error you're looking for. Better reassign computerChoice instead e.g.

computerChoice = "rock"


I tried excluding it but it still did not work


Here you go

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"


Thanks for your help.


I was just about to ask the same questions. Glad I found this thread. Thanks!


the reason why I didn't attempt it like this is because of the ranges. wouldn't this be incorrect because .33 could fall under rock or paper?


No 0.33 fulfils this condition:

if (computerChoice <= 0.33) {

and so it is rock. The paper condition would only be considered if this was false.


ahh I see, thanks for clearing that up! Forgot that it goes down the conditions like that.