html - I don't know why my function Flip() in JavaScript isn't returning anything. I want it to return if it is heads or tails -
javascript - don't see obvious wrong
function flip() { var probability = math.floor(math.random()); if (probability > 0.5) { document.getelementbyid("message").innerhtml("heads!"); } if (probability < 0.5) { document.getelementbyid("message").innerhtml("tails!"); }
html - nothing should wrong in html (besides selectors)
<body> <button onclick="flip()" id="submit">flip coin</button> <p id="message"></p> </body>
you should assign innerhtml below, not function. check demo - fiddle.
function flip() { var probability = math.floor(math.random()); if (probability > 0.5) { document.getelementbyid("message").innerhtml = "heads!"; } if (probability < 0.5) { document.getelementbyid("message").innerhtml = "tails!"; } }
Comments
Post a Comment