javascript - computerChoice is not a function error -


so having problems making rock, paper , scissors game. keep getting error "typeerror: computerchoice not function" can see why happening, don't know how fix it.

heres code;

var userchoice = prompt("do chose 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 < 1)  {     computerchoice("scissors"); } 

ive been told since var isn't function problem, how fix it. tried var computerchoice = function (math.random()); still didn't work.

thanks whoever can me! :)

you have assign value variable. here's code.

http://jsfiddle.net/neoares/vespwott/

var userchoice = prompt("do chose rock, paper or scissors?"); var rnd = math.random();  var computerchoice;  if (rnd < 0.33)  {     computerchoice = "rock"; }  else if (rnd < 0.66) {     computerchoice = "paper"; }  else  {     computerchoice = "scissors"; } alert("random: "+rnd+"\ncomputerchoice: "+computerchoice); 

Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -