<!DOCTYPE html> <html lang="en-us"> <head> <meta charset="utf-8" /> <title>Roll to Hit!</title> <meta name="description" content="Roll to Hit! - Version 0.5" /> <meta name="author" content="Carson Beck" /> <meta name="dcterms.rights" content="https://creativecommons.org/licenses/by-sa/4.0/" /> </head> <!-- start of visible page --> <body> <p id="prompt">Roll the to hit the evil Ogre!</p> <input type="button" value="Roll" onclick="RolltoHit();" /> <!-- JavaScript code placed at end of <body> element --> <script> function RolltoHit() { var randomNumber = Math.floor((Math.random() * 20) + 1); if (randomNumber.value >= 10) { document.getElementById("prompt").innerHTML = randomNumber + " You hit!"; } else if (randomNumber.value <= 9) { document.getElementById("prompt").innerHTML = randomNumber + " You miss the Ogre!"; } else if (randomNumber.value == 20) { document.getElementById("prompt").innerHTML = "Natural 20! The beast is slain!"; } else if (randomNumber.value == 1) { document.getElementById("prompt").innerHTML = "Natural 1! You dropped your sword!"; } } </script> </body> </html>
if
randomNumber
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)