TurnoverEwe0633
TurnoverEwe0633

Reputation: 7

JavaScript/HTML Code In Variables?

I am designing a monopoly style digital game and want a dice rolling button so i tried this:

<button class="bttnrolldice" onclick="diceRoll()">Roll Dice</button><h1 id="rollresults"></h1> 
<script>
    function diceRoll() {
            var die1 =  math.ceil(math.random() * 7;
            var die2 =  math.ceil(math.random() * 7;
            document.getElementById("rollresults").innerHTML = (die1 + die2); }
</script>

Whenever I run the code, nothing shows up below the button. Can you give me a hand? (It might have something to do with the variables that equal js code, if so tell me how to fix this.)

Upvotes: 0

Views: 49

Answers (3)

Lixus
Lixus

Reputation: 511

You are missing closing parenthesis on your Math.ceil functions

<button class="bttnrolldice" onclick="diceRoll()">Roll Dice</button><h1 
id="rollresults"></h1> 
<script>
    function diceRoll() {
       var die1 =  Math.ceil(Math.random() * 7);
       var die2 =  Math.ceil(Math.random() * 7);
       document.getElementById("rollresults").innerHTML = (die1 + die2); 
   }
</script>

Upvotes: 1

Tester
Tester

Reputation: 117

You are missing a right parentheses on line 4 and line 5.

When running your script in Google Chrome, press [F12] and the error will be described on the Console tab.

Upvotes: 1

Vaibhav Nigam
Vaibhav Nigam

Reputation: 1467

Inspect element and check browser console for errors.

  1. It should be "Math" instead of "math".
  2. Closing parenthesis are missing in statements where die1 and die2 variables are declared.

Upvotes: 0

Related Questions