I don't know what is wrong with my code


#1

var userChoice = prompt("Do you choose rock, paper or scissors?")
var computerChoice = Math.random()
console.log(computerChoice)
if (computerChoice===0-0.33 ) { computerChoice = rock}
else if (computerChoice === 0.34-0.66) {computerChoice = paper}
else {computerChoice = scissors}
it says scissors is not defined


#2

Hey @empathicchain6,

Those two don't make sense.

Why:

  • The signal '-' means to subtract. That means that in the if loop, it means that 0 subtracted by 0.33, which doesn't make sense.

  • computerChoice cannot equal to 0 subtracted by 0.33, which is -0.33 because the Math.random function only counts from 0 to 1.

Solutions:

  • Instead of using 0-0.33, 0.34-0.66, etc, we can just use the comparators < and >. Then we can get the numbers between those two numbers. Ex: computerChoice < 0.33 Ex(2): computerChoice <0.67
  • Do not make the equalization/comparing to a negative, for Math.random does not reach that (in this situation)

Hope it helped!:smiley: