Skip to content

Commit 88602b5

Browse files
committed
fixes readme and tests for inclusivity, adjusts based on linter rules
1 parent df37fa6 commit 88602b5

File tree

2 files changed

+37
-18
lines changed

2 files changed

+37
-18
lines changed

README.md

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,15 @@ for ([initialization]; [condition]; [iteration]) {
8080
**_Usage_**: Use a `for` loop when you know how many times you want the loop to
8181
run (for example, when you're looping through elements in an array).
8282

83-
#### Examples
83+
### Examples
8484

8585
Let's take a look at an example and get some practice using the Node debugger.
8686
Enter the code below into the `index.js` file.
8787

88-
> **Note:** You can, of course, copy/paste the code rather than typing it in yourself, but we recommend typing it in for now. The act of typing code develops muscle memory and helps your brain understand and internalize the syntax.
88+
> **Note:** You can, of course, copy/paste the code rather than typing it in
89+
> yourself, but we recommend typing it in for now. The act of typing code
90+
> develops muscle memory and helps your brain understand and internalize the
91+
> syntax.
8992
9093
```js
9194
for (let age = 30; age < 40; age++) {
@@ -115,8 +118,9 @@ loop, we increment `age` to `32`, and so on.
115118
The **loop body** is the set of statements that we want to run when the
116119
condition evaluates to `true`.
117120

118-
Let's take a look at what's happening in our loop using debugger. Run `node inspect index.js` in the terminal to start the debugger. You should see the
119-
following:
121+
Let's take a look at what's happening in our loop using debugger. Run
122+
`node inspect index.js` in the terminal to start the debugger. You should see
123+
the following:
120124

121125
![Debugger Output 1](https://curriculum-content.s3.amazonaws.com/phase-0/looping-code-along/debugger_1.png)
122126

@@ -139,7 +143,8 @@ can verify the value of `age` by entering the REPL and typing `age` at the
139143
prompt, then exit the REPL to continue stepping through. When you're done, enter
140144
`.exit` or `Ctrl-C` twice to exit the debugger.
141145

142-
Now let's remove `debugger;` from our code and execute it by running `node index.js`. You should see the following:
146+
Now let's remove `debugger;` from our code and execute it by running
147+
`node index.js`. You should see the following:
143148

144149
![Happy Birthday logged](https://curriculum-content.s3.amazonaws.com/phase-0/looping-code-along/happy-birthday-to-me.png)
145150

@@ -170,13 +175,15 @@ than `gifts.length` (`3` in the above example). Our iteration, `i++`, increments
170175
our counter by `1` at the end of each pass through the loop.
171176

172177
Run `node inspect index.js` in the terminal to enter the debugger, and `cont` at
173-
the `debug` prompt to advance to the breakpoint. You should see `Wrapped teddy bear and added a bow!` logged. In our loop body, we reference `gifts[i]`. Since
174-
`i` starts out as `0`, during the first pass through the loop `gifts[i]` is
175-
`gifts[0]`, which is `'teddy bear'`. Continue stepping through the loop by
176-
entering `cont` at the`debug` prompt and remember you can enter the REPL at any
177-
point to check the values of our variables, `i` and `gifts[i]`.
178+
the `debug` prompt to advance to the breakpoint. You should see
179+
`Wrapped teddy bear and added a bow!` logged. In our loop body, we reference
180+
`gifts[i]`. Since `i` starts out as `0`, during the first pass through the loop
181+
`gifts[i]` is `gifts[0]`, which is `'teddy bear'`. Continue stepping through the
182+
loop by entering `cont` at the`debug` prompt and remember you can enter the REPL
183+
at any point to check the values of our variables, `i` and `gifts[i]`.
178184

179-
When you're done, remove the `debugger` and execute the code by running `node index.js`. You should see the following logged to the terminal:
185+
When you're done, remove the `debugger` and execute the code by running
186+
`node index.js`. You should see the following logged to the terminal:
180187

181188
```text
182189
Wrapped teddy bear and added a bow!
@@ -191,7 +198,11 @@ of gifts and loop over them, logging our own message. Let's practice that with a
191198
slightly different idea. To complement our gift wrapping function, your task is
192199
to create a thank you card creator.
193200

194-
> **Note**: Recall the difference between logging and returning values from a function. When we log information we are simply outputting text to a terminal or console. When we return data from a function we will be able to reference and use that information elsewhere because the data is being passed out of the function.
201+
> **Note**: Recall the difference between logging and returning values from a
202+
> function. When we log information we are simply outputting text to a terminal
203+
> or console. When we return data from a function we will be able to reference
204+
> and use that information elsewhere because the data is being passed out of the
205+
> function.
195206
196207
In `index.js`, build a function named `writeCards()` that accepts two arguments:
197208
an array of string names, and an event name. Create a `for` loop with a counter
@@ -215,21 +226,26 @@ array.) The overall process should be:
215226
Here is an example of what a call to the `writeCards()` function might look like:
216227

217228
```js
218-
writeCards(["Ada", "Brendan", "Ali"], "birthday");
229+
writeCards(["Charlie", "Samip", "Ali"], "birthday");
219230
```
220231

221232
If we were to call the function using this function call, it should produce the
222233
following array as the return value:
223234

224235
```js
225236
[
226-
"Thank you, Ada, for the wonderful birthday gift!",
227-
"Thank you, Brendan, for the wonderful birthday gift!",
237+
"Thank you, Charlie, for the wonderful birthday gift!",
238+
"Thank you, Samip, for the wonderful birthday gift!",
228239
"Thank you, Ali, for the wonderful birthday gift!",
229240
];
230241
```
231242

232-
> **Top Tip**: The debugger isn't just for debugging code — you can also use it to help you write your function! Try building the structure of the loop, putting the `debugger` inside the loop body. Even before you start writing the code, you can enter the debugger's REPL and try out code until you figure out how to create the message and add it to an array. Once it's working in the REPL, transfer the code to `index.js`, exit the debugger, and run the tests.
243+
> **Top Tip**: The debugger isn't just for debugging code — you can also use it
244+
> to help you write your function! Try building the structure of the loop,
245+
> putting the `debugger` inside the loop body. Even before you start writing the
246+
> code, you can enter the debugger's REPL and try out code until you figure out
247+
> how to create the message and add it to an array. Once it's working in the
248+
> REPL, transfer the code to `index.js`, exit the debugger, and run the tests.
233249
234250
## The `while` loop
235251

test/indexTest.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,11 @@ describe( 'index.js', () => {
1414
describe( 'writeCards()', () => {
1515

1616
it( 'returns an array of thank you messages for each name provided to the function', () => {
17-
expect( writeCards( [ 'Lisa', 'Kaitlin', 'Jan' ], 'surprise' ) )
18-
.to.deep.eq( [ 'Thank you, Lisa, for the wonderful surprise gift!', 'Thank you, Kaitlin, for the wonderful surprise gift!', 'Thank you, Jan, for the wonderful surprise gift!' ] );
17+
expect(writeCards(["Guadalupe", "Ollie", "Aki"], "surprise")).to.deep.eq([
18+
"Thank you, Guadalupe, for the wonderful surprise gift!",
19+
"Thank you, Ollie, for the wonderful surprise gift!",
20+
"Thank you, Aki, for the wonderful surprise gift!",
21+
]);
1922
} );
2023
} );
2124

0 commit comments

Comments
 (0)