- Populate an Array
Loading sequential numbers into an array supposedly as part of teaching how to write a FOR loop where no loop is actually required.
- Create a Multiplication Table
- Guessing Game
The right way to do this one is using a form and an event listener.
- Adding Sequential Numbers
While a loop may be the most obvious way to solve a problem and while it may work for a few simple test cases, it may not be the appropriate in the real world.
- Just the Consonants
This question can be easily solved with a regular expression but may be asked in beginner classes where the simple solution has not yet been taught.
- Coloured letters
This question could be appropriate for a programming class, it all depends on what stage it is given. The historical answer uses prompt, document.write and a loop while a modern answer uses DOM calls and array methods.
- Triggering Events
Here we look at not quite so antiquated code that is still jumbled with the HTML and compare it to a more modern unobtrusive version.
- Toggle Squares
Expanding further on event triggering, here we use just one event listener where the historical approach would have required 64 event handlers. As a modern question the answer requires an understanding of the DOM.
- Random Numbers
The modern way of providing numbers in a random order involves shuffling an array. What you can do with the numbers afterward is therefore far more flexible than using document.write to output them as they are randomly chosen.
By providing some standard library code we can ask a question at a completely different stage in the course to test for something completely different. Here we look at how a question that historically was about writing loops becomes a question about updating the DOM for modern courses.
- Non-Duplicate Integer Arrays
- Alternate Approaches
When providing a modern answer to an historical question you need to decide just how much of the irrelevant criteria that you are going to follow. Here we look at two modern answers to the same question one of which at least includes some of the statements the question seems to think should be used.
- Repeating Letters
Here we have a slightly ambiguous question where one interpretation was much easier to answer using a historical approach. Both alternatives can be easily answered with a more modern approach.
- Array Methods
This question is obviously testing for knowledge of the various modern array methods so why would you expect an historical answer involving lots of for loops?
- Odds and Evens
Simply done by overriding the sort comparison operator but how would you do it if you didn't know you could do that..
This article written by Stephen Chapman, Felgall Pty Ltd.