Basic While Loops - Write 4 words Version 3 - Random Words chosen

Writes each word as it gradually builds up 4 random words (using a while loop, and an if statement)-- until all words have been written:


This example of randomness randomly chooses 4 words from a total of 7 possible word choices.
Because this is relatively uncontrolled randomness, this example does NOT prevent the same word being randomly chosen more than once.

If the alert wasn't happening between each loop iteration, the 4 words would be written extremely quickly.

So if you want the loop just to create/execute something quickly, take the alerts out.

But if you want the loop to execute more slowly, the easiest solution is to EITHER:
- Keep the alerts
- Use a different method and NOT a loop (it is hard to safely slow loops down - crashes and errors tend to result).
      (a good way to get a slower effect could be a JS setTimeout [see the week 11 section of the Resources page] which calls a function that builds something up step by step in a global variable)