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

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -