Page is a not externally linkable
- Code, Content, and Presentation
-- JavaScript and AJAX
---- getting a global variable to update every setInterval call


birdbrain - 1:04 pm on May 4, 2012 (gmt 0)


Hi there cybernoob,

here is your code, tidied up a little...

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="language" content="english">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">

<title>assignment 6</title>

<style type="text/css">
body {
color:#000;
background-color:#fff;
}
a {
color:#00f;
}
a:visited {
color:#800080;
}
a:hover {
color:#008000;
}
a:active {
color:#f00;
}

#gameContainer {
width:50%;
height:200px;
border:1px solid #000;
margin:auto;
}
#button{
margin:5px 0 0 20%;
margin-top:5px;
float:left;
}
#statsBox {
padding:10px;
border:1px solid #000;
margin:5px 0 0 10%;
float:left;
}
#statsBox div {
margin:6px;
}
</style>

<script type="text/javascript">

function clock(){

if(time>0){
time--;

if(time<10){
time='0'+time;
}
document.getElementById('time').innerHTML=time;
}
else {
clearTimeout(t);
play=false;
return;
}
t=setTimeout(function(){clock()},1000)
}

function buttonPress() {
alert('this is working OK');
}

function init(){

time=30;

document.getElementById('button').onclick=function() {
buttonPress();
}
document.getElementById('play').onclick=function() {
clock();
}
}
window.addEventListener?
window.addEventListener('load',init,false):
window.attachEvent('onload',init);
</script>

</head>
<body>

<div id="gameContainer">

<button id="button">Click Me!</button>

<div id="statsBox">
<div>Time:<span id="time">30</span></div>
<div>Score:<span id="score">0</span></div>
<div>High Score:<span id="highScore">0</span></div>
<div><button id="play">play!</button></div>
</div>

</div>

</body>
</html>

bordbrain


Thread source:: http://www.webmasterworld.com/javascript/4449318.htm
Brought to you by WebmasterWorld: http://www.webmasterworld.com