mercredi 17 octobre 2018

Javascript Submit Button Random Coin Toss

Hopefully this is a quick fix. I have a coin toss generator that functions correctly (yay!) But I would like to be able to hit the flip button multiple times and run the function without having to reload and refresh the page.

<!DOCTYPE html>
<html>
<head>

    <title>Guess the Number!</title>
</head>
<body>
    <h1>Guess the Number!</h1>
    <p>See if you can guess the number between 1 and 50</p>
    <label for="guess"> Enter Your Guess </label>
    <input type="text" id="guess"><br>
    <button id="submit" onclick="junction();">Submit Guess</button>
    <p id="response"></p>
</body>
<script src="app.js"></script>
</html>

var randomNumber=Math.floor(Math.random()*2)+1;

document.getElementById("flip").onclick =function(junction){

if(randomNumber==1){
    document.getElementById("response").innerHTML ="Heads!";

}
else {
    document.getElementById("response").innerHTML ="Tails!";
}
}




Aucun commentaire:

Enregistrer un commentaire