Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
126 changes: 126 additions & 0 deletions courses/foundation/intro-to-javascript/week3/session-plan.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- Let the trainees explain iterating an array of objects
- Use real world examples (users, products, house listings)
- [Code inspiration](#inspiration-objects)
- Then: [Task 1: My Pet](#task-1-my-pet)
- Arrays continued
- `pop`, `push`, `shift`, `unshift`
- Let trainees investigate `shift` and `unshift`
Expand All @@ -15,6 +16,7 @@
- Looping through an array
- No `forEach`, `map`, `filter` or `reduce`
- [Code inspiration](#inspiration-arrays)
- Then: [Task 2: Shopping List](#task-2-shopping-list), [Task 3: Countdown to Launch](#task-3-countdown-to-launch), [Task 4: Student Grades](#task-4-student-grades)
- [CodeWar exercises](#codewar-exercises)
- Call stack
- Used for figuring code flow in js! Where does my function go when it is done here.
Expand Down Expand Up @@ -160,6 +162,130 @@ a();

## Exercises

> **Note:** Start with the practice tasks below — they reuse the same operations from the class demos. When those feel comfortable, move on to the CodeWars exercises.

### Task 1: My Pet

Topic: Objects — creating, updating, and deleting properties.

You just got a new pet! Let’s create an object to store information about it.

1. Create an object called `pet` with three properties:
- `name`: `"Buddy"`
- `type`: `"dog"`
- `age`: `2`
2. Print the pet’s name to the console.
3. Buddy just had a birthday! Update the age to `3`.
4. Add a new property called `color` with the value `"brown"`.
5. Delete the `type` property.
6. Print the entire object to the console.

Expected final result:

```js
{
name: "Buddy",
age: 3,
color: "brown"
}
```

### Task 2: Shopping List

Topic: Arrays — iterating from first to last.

You’re going grocery shopping and want to print your shopping list.

Starter code:

```js
const shoppingList = ["Milk", "Bread", "Eggs", "Apples", "Cheese"];
```

1. Use a `for` loop to go through the array from first to last.
2. Print each item with its position number (starting from 1).
3. After the loop, print the total number of items.

Expected output:

```text
1. Milk
2. Bread
3. Eggs
4. Apples
5. Cheese
Total items: 5
```

Bonus: Print `"Don’t forget the eggs!"` when you encounter `"Eggs"`.

### Task 3: Countdown to Launch

Topic: Arrays — iterating from last to first.

You’re preparing a rocket for launch! The countdown numbers are stored in an array, but they’re in the wrong order.

Starter code:

```js
const countdown = [1, 2, 3, 4, 5];
```

1. Use a `for` loop to go through the array from last to first.
2. Print each number to the console.
3. After the loop, print `"🚀 Blast off!"`.

Expected output:

```text
5
4
3
2
1
🚀 Blast off!
```

Bonus: Make sure your code works with any length of the countdown array.

### Task 4: Student Grades

Topic: Arrays of objects — iterating and modifying objects.

You’re helping a teacher manage student information. Each student has a name and a test score.

Starter code:

```js
const students = [
{ name: "Alice", score: 85 },
{ name: "Bob", score: 42 },
{ name: "Charlie", score: 73 },
{ name: "Diana", score: 95 },
{ name: "Eve", score: 38 },
];
```

1. Use a `for` loop to go through all students.
2. Add a new property called `passed` to each student.
3. Set `passed` to `true` if their score is 50 or higher, otherwise `false`.
4. Print each student’s name and whether they passed.
5. Print the updated `students` array.

Expected final result:

```js
[
{ name: "Alice", score: 85, passed: true },
{ name: "Bob", score: 42, passed: false },
{ name: "Charlie", score: 73, passed: true },
{ name: "Diana", score: 95, passed: true },
{ name: "Eve", score: 38, passed: false },
]
```

Bonus: Count how many students passed and print the result.

## Exercise: Call stack

Draw the call stack array at every draw point
Expand Down
Loading