Hello, I am having an issue with my HTML experiment... (Inserting JavaScript) -
technically, have link leads script of mine (sorry indentation if incorrect):
<!doctype html> <html> <title>game</title> <script> var userchoice = prompt("do choose rock, paper or scissors?"); var computerchoice = math.random(); if (computerchoice < 0.34) { computerchoice = "rock"; } else if (computerchoice <= 0.67) { computerchoice = "paper"; } else { computerchoice = "scissors"; } console.log("computer: " + computerchoice); var compare = function(choice1, choice2){ if (choice1 === choice2){ return "the result tie!"; } else if (choice1 === "rock"){ if (choice2 === "scissors") { return "rock wins"; } else { return "paper wins"; } } else if (choice1 === "paper"){ if (choice2 === "rock"){ return "paper wins"; } else { return "scissors wins"; } } else if (choice1 === "scissors"){ if (choice2 === "paper"){ return "scissors wins" } else { return "rock wins" } } } compare(userchoice, computerchoice); </script> <body> <h1>the rock paper scissors game</h1><br> <p>yaaaay!</p> </body> </html>
so, problem script runs to var userchoice = prompt("do choose rock, paper or scissors?")
when input answer, nothing happens.
what's wrong?!
buzzysin
your code fine, need result of compare. like:
alert(compare(userchoice, computerchoice));
see fiddle: https://jsfiddle.net/upcbdl6y/
Comments
Post a Comment