Using text box info as variable in Javascript? -


so, i'm making rock,paper,scissors game using javascript , i'm having trouble starting. need have text box , submit button, user input of "rock", "paper", "scissors" played against computer's random choice. how have computer take what's entered text field , run against computers choice? i'm novice , in need of nudge in right direction, because i'm not sure how start problem.

thanks

edit: so, friend sent me code , added onto of , looks work(at least me), i'm not sure set variable "player" equal in order equal textbox information.

var player =    var choices = ["rock","paper","scissors"]; var computer = choices[math.floor(math.random()*3)];  var win = "your "+player+" beats "+computer+". win."; var lose = "your "+player+" loses "+computer+". lose."; var draw = "a draw: "+player+" on "+computer+".";  if(player === "rock"){     if(computer === "scissors"){         result = win;         alert="win";     }     else if(computer === "paper"){         result = lose;         alert="lose";     }     else if(computer === "rock"){         result = draw;         alert="draw";     } } else if(player === "paper"){     if(computer === "rock"){         result = win;         alert="win";     }     else if(computer === "scissors"){       result = lose;         alert="lose";     }     else if(computer === "paper"){         result = draw;         alert="draw";     } } else if(player === "scissors"){     if(computer === "paper"){         result = win;         alert="win";     }     else if(computer === "rock"){         result = lose;         alert="lose";     }     else if(computer === "scissors"){         result = draw;         alert="draw";     } } </script> </head> <body> <form> <input type="text" id="rocktextinput" size="100" placeholder="rock, paper, or scissors" > <input type="button" id="button" value="play hand"> </form>  </body> </html> 

the computer's choice generated this:

... var plays = ["rock", "paper", "scissors"]; var rand = math.round(math.random() * 2);  alert("computer played: " + plays[rand]);  //check see winner ... 

hope helps give start.


Comments

Popular posts from this blog

ios - iPhone/iPad different view orientations in different views , and apple approval process -

java Extracting Zip file -

C# WinForm - loading screen -