There are many issues:
1. It should be
Math.random()
not
Math.Random()
JavaScript random() Method[
^]
and it returns a floating number, not integer that you wanted, you have to floor it using Math.floor() method.
2. The default behaviour of a form submit is to submit the form data to server-side and refresh the page itself, that explained why you got a blank page after pressing the submit button. To cancel this default behaviour, you have to return false from your JavaScript function, e.g.
<form onsubmit="return Game()">
function Game() {
return false;
}
3. Whom do you expect these code to "return" their value to?
if (ComputerChoice == 1) {
return "Rock";
}
if (ComputerChoice == 2) {
return "Paper";
}
if (ComputerChoice == 3) {
return "Scissors";
}
if (ComputerChoice == 4) {
return "Spock";
}
if (ComputerChoice == 5) {
return "Lizard";
}
You should put them inside a function, and call it from inside the Game().
4. Why is there this onsubmit="UserChoice" in here? Remember to enclose the id value with quotes.
<input type="text" id=user onsubmit="UserChoice" placeholder="Make your choice...">
5. Use if...else if... construct to avoid having to check through all if's
JavaScript If...Else Statements[
^]
6. Lastly, you are trying to display the result inside a input textbox with h1 tag, it will not work.
You should display the result in another placement div, e.g.
<div id="result"></div>
Then display the result in this div thru JavaScript, e.g.
document.getElementById('result').innerHTML = "<h1>You lost! The computer chose</h1>" + ComputerChoice;