The recent Javascript Incrementing and Decrementing Primer Tutorial broached …
- prefix syntactical Javascript Incrementing and Decrementing of variables … and, today, we extend that to …
- suffix syntactical Javascript Incrementing and Decrementing of variables … and to …
- both
… but in adding that new functionality, we baulked that little bit because in order to do this in most of the scenarios of our changed plus_avoids_zero.html‘s web application live run link, it required multiple Javascript commands per single HTML button element click/tap. We figure you’ll forgive us in the sense that our semicolon (“;”) based delimited set of commands could be fed through a Javascript eval (though we don’t) to achieve the single button click/tap per single (eval) act, anyway.
As well, in executing the web application here and now look, the HTML button “looks” (helped out by yesterday’s HTML Button Element Whitespace Primer Tutorial) we hope the patterns help you out with the way this Incrementing and Decrementing can work in Javascript.
Previous relevant Javascript Incrementing and Decrementing Primer Tutorial is shown below.
Sometimes writing Javascript code we’ve let code like …
<script type='text/javascript'>
var counter=null;
function initializeCounter() {
counter=0;
}
function incrementCounter() {
if (counter == null) {
counter=0;
}
++counter;
}
if (eval(Math.floor(Math.random() * 1746765765) % 2) == 1) {
initializeCounter();
} else {
incrementCounter(); // if called first, is interesting
}
</script>
… go through to the keeper. There’s nothing intrinsically wrong with it. But the other day, thanks to Device Orientation ‘alpha’
Calibration … World-based calibration on iOS, we learnt that the “if” bracketing above can be superfluous in the sense that that same code above could be written …
<script type='text/javascript'>
var counter=null;
function initializeCounter() {
counter=0;
}
function incrementCounter() {
++(+counter); // ... more succinctly
}
if (eval(Math.floor(Math.random() * 1746765765) % 2) == 1) {
initializeCounter();
} else {
incrementCounter(); // if called first, is interesting
}
</script>
And so, we thought we’d write today’s proof of concept plus_avoids_zero.html‘s live run link in order for a user to try out some “Prefix style” incrementing and decrementing of Javascript variables …
If this was interesting you may be interested in this too.
If this was interesting you may be interested in this too.




Naming the things in a bathroom is a smarter vocabulary exercise than it first looks, because every learner already knows the room, so the words attach to objects they can see and touch instead of floating on a flashcard. Asking how many things can you name turns it into a game rather than a test, and the counting itself becomes the motivation: one more word than last time is a visible win. I like the way this kind of lesson uses a photograph as the prompt, since a picture gives every student the same starting point regardless of level, and the stronger students can move on to describing what each thing is for while beginners are still collecting nouns. The bathroom is a good choice of room too, because it is full of everyday words that textbooks often skip, the small objects people actually say out loud every morning. A daily habit of naming five new things around the house would build a working vocabulary faster than memorising lists, and this post is a good template for it.