EXERCISE A: a short story
In this exercise, try telling a short story using JavaScript.
Here the steps you’ll need to take:
- Create a variable that contains all of the lines of your story (this should be an array of strings)
- Create a variable that tracks your place in the array (this should be a number)
- Create a function that does the following:
- Increases your tracking variable by 1
- Reads the entry in the array that corresponds to the tracking variable
- Outputs that string via alert()
- Checks if the end of the array has been reached, and restarts if needed
- Add that function to a button via the onclick attribute