SO - 29380956
by Arun P Johny
HTML
<img id="die" alt="die" />
<br/>
<input type="button" value="Click me!" onclick="displaydie()" />
<span id="total"></span>
JavaScript
var total = 0;
function displaydie() {
var num = (Math.floor(Math.random() * 6) + 1);
total += num;
document.getElementById("die").setAttribute("src", num + ".jpg")
document.getElementById("total").innerHTML = total;
}