Skip to content

Workshop on JavaScript objects and loops

For this workshop, tell a story using JavaScript objects, arrays, and loops.

You can use any story you like, including re-using the story you wrote for the JS Values and Variables workshop. Try having a browse through Aesop’s fables to see if one of those stories captures your imagination.

Here are a few promising fables that have a nice story, action, and even some repetition that can be used for arrays and loops:

Steps

  1. Create a GitHub repository from the link on Moodle.

  2. Create an index.html, an index.js or script.js, and link them together.

  3. Write your story in the JS file. Your program does not have to modify or output anything to the HTML, just the browser console.

Structure tip

Try breaking the story down into sections, like the situation, the action, and the result. Before you start writing code, write the structure out using comments so you can see the overall shape.

Objects tip

Make your characters into objects, assign their qualities as object properties, and program their behaviors by means of object methods.

Arrays and loops tip

To use an array in your program, think about what part of the story is repeated several times. Then write an array that contains the information about the repeated actions. Then loop over that array to make the action happen.

Requirements checklist

For homework credit, here are the main things to try to get right:

  • At least one object with properties that are accessed or changed in the program.
  • At least one array (or string) that is iterated over using a loop.
  • The variable, property, and method names make sense and are consistently styled.
  • The program tells a story.
  • Key information is logged to the console.
  • There are no errors when the program runs.

Content CC BY 4.0 | Code AGPL 3.0