Javascript Help?

  You are currently not logged in. You can view the forums, but cannot post messages. Log In | Register

21-Feb-12 20:13
I am working on a project for school in which I need to create a web page that simulates the tossing of dice. I've done that. I need to include three <span> tags: the first counting the number times I click "roll", the second counting the number of times I roll doubles, and the third being the percentage of times I have rolled doubles in regards to my overall rolling. I have done the first two easily but I'm struggling with the third <span> tag. Here's what I've done so far:



var numOfRolls = parseInt(document.getElementById('rollSpan').innerHTML);
var numOfDoubles = parseInt(document.getElementById('doubleSpan').innerHTML);
var num = parseInt('numOfDoubles' / 'numOfRolls');
var percentDoubles = num.toFixed(2);



And in the <body>:


<span id="percentSpan">0.0</span> % of your rolls are doubles.



I'm having trouble getting a value to show up in this span tag. What am I doing wrong?
27-Feb-12 21:10
@arianag: How about:


document.getElementById('percentSpan').innerHTML = percentDoubles;


--
Matt Doyle, Elated
3rd Edition of my jQuery Mobile book out now! Learn to build mobile web apps. Free sample chapter: http://store.elated.com/

 
New posts
Old posts

Follow Elated