Skip to content

Commit 4e79998

Browse files
committed
Objects homework
1 parent 1d39ff6 commit 4e79998

8 files changed

Lines changed: 44 additions & 836 deletions

File tree

outline.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,10 +226,10 @@ export const outline = [
226226
text: 'Live coding',
227227
link: '/lectures/objects-loops-live-coding.html',
228228
},
229-
// {
230-
// text: 'Workshop',
231-
// link: '/workshops/objects/index.html',
232-
// },
229+
{
230+
text: 'Workshop',
231+
link: '/workshops/objects/index.html',
232+
},
233233
]
234234
},
235235
// {

workshops/objects/index.md

Lines changed: 40 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -1,111 +1,58 @@
1-
# Workshop on JavaScript objects, loops, and files
1+
# Workshop on JavaScript objects and loops
22

3-
## Part 1: Practical
3+
For this workshop, tell a story using JavaScript objects, arrays, and loops.
44

5-
The practical part of today’s workshop is mostly in one file, “shapes.js”.
6-
Download it to get started.
5+
You can use any story you like, including re-using the story you wrote for the [JS
6+
Values and Variables](http://localhost:5173/web-development/workshops/values-variables/)
7+
workshop. Try having a browse through [Aesop’s
8+
fables](https://www.read.gov/aesop/) to see if one of those
9+
stories captures your imagination.
710

8-
There are some optional steps at the end that also require two other files:
9-
“extraColors.js” and “package.json”. Download both files or
10-
copy-paste into your own versions to get started. Then follow the
11-
instructions in “shapes.js”.
11+
Here are a few promising fables that have a nice story, action, and even some repetition that can be used for arrays and loops:
1212

13-
[Download shapes.js](https://github.com/Birkbeck2/web-development/blob/main/workshops/objects/starter-files/shapes.js)
13+
- [The Crow & the Pitcher](https://www.read.gov/aesop/012.html)
1414

15-
<<< @/workshops/objects/starter-files/shapes.js{js}
15+
- [The Oak and the Reeds](https://www.read.gov/aesop/011.html)
1616

17-
[Download extraColors.js](https://github.com/Birkbeck2/web-development/blob/main/workshops/objects/starter-files/extraColors.js)
17+
- [The Heron](https://www.read.gov/aesop/015.html)
1818

19-
<<< @/workshops/objects/starter-files/extraColors.js{js}
19+
- [The Hare and the Tortoise](https://www.read.gov/aesop/025.html)
2020

21-
[Download package.json](https://github.com/Birkbeck2/web-development/blob/main/workshops/objects/starter-files/package.json)
21+
- [The North Wind and the Sun](https://www.read.gov/aesop/143.html)
2222

23-
<<< @/workshops/objects/starter-files/package.json{json}
23+
## Steps
2424

25-
## Part 2: Creative
25+
1. Create a GitHub repository from the link on Moodle.
2626

27-
Choose one of the three options below.
27+
2. Create an `index.html`, an `index.js` or `script.js`, and link them together.
2828

29-
## Creative option A: Make something!
29+
3. Write your story in the JS file. Your program does not have to modify or
30+
output anything to the HTML, just the browser console.
3031

31-
Scenario: Choose something that you can represent in code with arrays and
32-
objects. It can be info about some of your favorite songs, TV shows,
33-
clothes, hobbies, pets, work, etc.
32+
::: tip Structure tip
33+
Try breaking the story down into sections, like
34+
the situation, the action, and the result. Before you start writing code,
35+
write the structure out using comments so you can see the overall shape.
36+
:::
3437

35-
Goal: Write a program including arrays, objects, and loops that uses that
36-
info to tell a story or investigate the answer to some questions about the
37-
info.
38+
::: tip Objects tip
39+
Make your characters into objects, assign their qualities as object properties,
40+
and program their behaviors by means of object methods.
41+
:::
3842

39-
## Creative option B: Explore 1980s hit song data
43+
::: tip Arrays and loops tip
44+
To use an array in your program, think about what part of the story is repeated
45+
several times. Then write an array that contains the information about the repeated
46+
actions. Then loop over that array to make the action happen.
47+
:::
4048

41-
### Scenario
49+
## Requirements checklist
4250

43-
You are a developer working on a music streaming app. You use
44-
JavaScript to work with data about songs, albums, artists, and audio
45-
generally. You’ve been provided with a list of top singles from the UK in
46-
the 1980s (see starter files below).
51+
For homework credit, here are the main things to try to get right:
4752

48-
### Goal
49-
50-
Ask some questions that the data can answer, using loops. Can’t
51-
think of any? Try these.
52-
53-
1. What’s the longest song title (in terms of number of characters)?
54-
2. What’s the shortest title?
55-
3. Is “I” or “You” used more often? How about “Me”? How about “Love”?
56-
4. What was the top ranked song for each year?
57-
5. Which artist appears on the list most often?
58-
6. Can you use a for loop to write an HTML document (a string) with markup
59-
for a `ul` and `li` items, using the data?
60-
61-
### Starter code
62-
63-
[Download songData.js](https://github.com/Birkbeck2/web-development/blob/main/workshops/objects/starter-files/songData.js) (too long to show here)
64-
65-
[Download songs.js](https://github.com/Birkbeck2/web-development/blob/main/workshops/objects/starter-files/songs.js)
66-
67-
<<< @/workshops/objects/starter-files/songs.js{js}
68-
69-
## Creative option C: Image factory (warning: challenging!)
70-
71-
### Scenario
72-
73-
You are a developer working on a web app where users can
74-
choose a color and download geometric shapes in that color. The shapes are
75-
made with SVG (scalable vector graphics), which is a markup language that
76-
can be used to encode graphics like logos, icons, and illustrations.
77-
78-
### Objective
79-
80-
In the starter code below, you are given a square, encoded
81-
using SVG markup. Create at least five copies of the square in different
82-
colors, and save them all as files in the folder called “output”.
83-
84-
### Starter code
85-
86-
[Download images.js](https://github.com/Birkbeck2/web-development/blob/main/workshops/objects/starter-files/images.js)
87-
88-
<<< @/workshops/objects/starter-files/images.js{js}
89-
90-
### Clues and tips
91-
92-
- Program structure: First create an array with all the color codes you want, or an
93-
object with color names and color codes as key-value pairs. Then you can
94-
iterate over this with a for loop to create one copy of the image for each
95-
color.
96-
97-
- SVG format: Don’t worry if you haven’t used SVG markup before--you
98-
already know some of it, because it’s similar to HTML and CSS in many
99-
ways. Look for familiar patterns. Can you tell where the color is
100-
defined in the code?
101-
102-
- Changing the colors: Once you have found the color definition in the SVG
103-
code, you’ll want to change it. Try looking up how the `replace()`
104-
method works on strings.
105-
106-
- Saving each file: You’ll need the built-in function called `writeFileSync()`,
107-
which is already imported for you on line 1. It is used like this:
108-
`writeFileSync('output-folder-name/file-name.txt', 'content of file as
109-
a string')`. Note: on Windows, you have to use backslash (`\`) between
110-
the folder name and file name, and on Mac and Linux, you have to use
111-
forward slash (`/`).
53+
- At least one object with properties that are accessed or changed in the program.
54+
- At least one array (or string) that is iterated over using a loop.
55+
- The variable, property, and method names make sense and are consistently styled.
56+
- The program tells a story.
57+
- Key information is logged to the console.
58+
- There are no errors when the program runs.

workshops/objects/starter-files/extraColors.js

Lines changed: 0 additions & 4 deletions
This file was deleted.

workshops/objects/starter-files/images.js

Lines changed: 0 additions & 33 deletions
This file was deleted.

workshops/objects/starter-files/package.json

Lines changed: 0 additions & 3 deletions
This file was deleted.

workshops/objects/starter-files/shapes.js

Lines changed: 0 additions & 90 deletions
This file was deleted.

0 commit comments

Comments
 (0)