javascript - When I run this, I get "TypeError: Number is not a function" -


var userchoice = prompt("do choose rock, paper, or scissors?") var computerchoice = math.random()     if(computerchoice(0 < 0.33))  {     computerchoice = ("paper"); } else if(computerchoice(0.34 < 0.66)) {     computerchoice = ("rock"); } else {     computerchoice = ("scissors"); } 

is there i'm missing in code? looks fine me.. anyway, said, when run this, typeerror mentioned above. trying paper if random number below .33, , rock if .34-.66, , scissors if .67-1.

whenever use math.random make variable number , trying have function.

your code should this:

var userchoice = prompt("do choose rock, paper, or scissors?") var computerchoice = math.random();     if(computerchoice < 0.33)  {     computerchoice = "paper"; } else if(0.34 < computerchoice && computerchoice < 0.66) {     computerchoice = "rock"; } else {     computerchoice = "scissors"; } 

where comparing random number number , not function

working fiddle

updated code per @anthony forloney


Comments

Popular posts from this blog

java - How to specify maven bin in eclipse maven plugin? -

single sign on - Logging into Plone site with credentials passed through HTTP -

php - Why does AJAX not process login form? -