I'm looking for (and be as brutal as you like) ways to improve the code or the algorithm (I'm aware there should be comments) - I'm a recreational programmer and would like to be improving my skills. My next step is to get the targetNumber
value from a nearby file without losing the current count.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Count to a particular target</title>
</head>
<body>
<h1 id="myDiv">Starting</h1>
<script type="text/javascript">
currentValue = 100;
targetValue = 1500;
function count() {
if (currentValue > targetValue) {
currentValue -= 1
} else if (currentValue < targetValue) {
currentValue += 1
}
document.getElementById('myDiv').innerHTML = 'Total wordcount:'+ currentValue.toString();
changeTime = 20;
if (Math.abs(currentValue - targetValue) < 980) {
changeTime = 1000 - Math.abs(currentValue - targetValue);
}
setTimeout(count,changeTime/2);
}
count()
</script>
</body>
</html>