Skip to content

Commit 177a051

Browse files
committed
Add narrative
1 parent 932bf4a commit 177a051

File tree

4 files changed

+114
-17
lines changed

4 files changed

+114
-17
lines changed

.results.json

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
{
2+
"stats": {
3+
"suites": 1,
4+
"tests": 3,
5+
"passes": 3,
6+
"pending": 0,
7+
"failures": 0,
8+
"start": "2016-06-22T18:02:54.382Z",
9+
"end": "2016-06-22T18:02:55.793Z",
10+
"duration": 1411
11+
},
12+
"tests": [
13+
{
14+
"title": "defines `greeting`",
15+
"fullTitle": "strings defines `greeting`",
16+
"duration": 1,
17+
"currentRetry": 0,
18+
"err": {}
19+
},
20+
{
21+
"title": "concatenates strings to greet a special guest in `greetSpecialGuest`",
22+
"fullTitle": "strings concatenates strings to greet a special guest in `greetSpecialGuest`",
23+
"duration": 0,
24+
"currentRetry": 0,
25+
"err": {}
26+
},
27+
{
28+
"title": "interpolates a string in `conversation`",
29+
"fullTitle": "strings interpolates a string in `conversation`",
30+
"duration": 0,
31+
"currentRetry": 0,
32+
"err": {}
33+
}
34+
],
35+
"pending": [],
36+
"failures": [],
37+
"passes": [
38+
{
39+
"title": "defines `greeting`",
40+
"fullTitle": "strings defines `greeting`",
41+
"duration": 1,
42+
"currentRetry": 0,
43+
"err": {}
44+
},
45+
{
46+
"title": "concatenates strings to greet a special guest in `greetSpecialGuest`",
47+
"fullTitle": "strings concatenates strings to greet a special guest in `greetSpecialGuest`",
48+
"duration": 0,
49+
"currentRetry": 0,
50+
"err": {}
51+
},
52+
{
53+
"title": "interpolates a string in `conversation`",
54+
"fullTitle": "strings interpolates a string in `conversation`",
55+
"duration": 0,
56+
"currentRetry": 0,
57+
"err": {}
58+
}
59+
]
60+
}

README.md

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,62 @@ Welcome to another JavaScript lab!
77

88
## Objectives
99

10+
In this lab, we're going to work with strings. Remember, strings in JavaScript are wrapped in single or double quotes, or in back ticks.
11+
12+
By the end of this lab, you'll
13+
1014
1. Manipulate strings by hand in JavaScript
1115
2. Practice interpolating with template literals
1216

1317
## Introduction
1418

15-
In this lab, we're going to work with strings. Remember, strings in JavaScript are wrapped in single or double quotes, or in back ticks.
19+
Imagine we're planning a birthday party for Bill Nye. There are going to be a lot of people there, so we're going to use JavaScript to help us keep everything straight.
20+
21+
First, we need to practice greeting everyone. (I don't know about you, but I sometimes get nervous and say the dumbest things — but we don't want to embarrass ourselves in front of Bill Nye!)
22+
23+
One might think that we could just type
24+
25+
``` javascript
26+
Hello, everybody!
27+
```
28+
29+
in our browser's console and be done with it. Give it a try.
30+
31+
You should see something like
32+
33+
``` shell
34+
Uncaught ReferenceError: Hello is not defined(…)
35+
```
36+
37+
Well, that won't work. (This is why we practice!) In order to greet our guests, we need to tell JavaScript that we're using a **string**. A string is a collection of characters (letters, numbers, and symbols) wrapped in single or double quotes (or, as we'll see, in back ticks). So to greet everyone, we can write,
38+
39+
``` javascript
40+
'Hello, everybody!'
41+
```
42+
43+
or
44+
45+
``` javascript
46+
"Hello, everybody!"
47+
```
48+
49+
They're the same in this case.
1650

17-
When we wrap strings in single or double quotes, we can join them together using the `+` operator:
51+
What if we want to say hi to a special guest, like Neil deGrasse Tyson? When we wrap strings in single or double quotes, we can join them together using the `+` operator:
1852

1953
``` javascript
20-
"Hello, " + "world!" // "Hello, world!"
54+
var specialGuest = "Neil deGrasse Tyson"
55+
"Hello, " + specialGuest + "!" // "Hello, Neil deGrasse Tyson!"
2156
```
2257

23-
This is called _concatenation_.
58+
This is called _concatenation_. Notice that `specialGuest` is _also_ a string!
2459

25-
Similarly, when we wrap strings in back ticks, we can use placeholders (`${}`) and insert variables or evaluated JavaScript directly:
60+
When we wrap strings in back ticks, we can use placeholders (`${}`) and insert variables or evaluated JavaScript directly:
2661

2762
``` javascript
28-
var thing = 'world'
63+
var specialGuest = "Neal deGrasse Tyson"
2964

30-
`Hello, ${thing}! High ${3 + 2}!` // "Hello, world! High 5!"
65+
`Hello, ${specialGuest}! High ${3 + 2}!` // "Hello, Neil deGrasse Tyson! High 5!"
3166
```
3267

3368
This is called _interpolation_.

strings.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
var myString = "";
1+
var greeting = "!";
22

3-
var concatenatedString = "A whole is the sum" + "";
3+
var specialGuest = "Neil deGrasse Tyson"
44

5-
var animal = 'cat';
5+
var greetSpecialGuest = "" + specialGuest + "!";
66

7-
var interpolatedString = `${animal}`;
7+
var topic = "space";
8+
9+
var conversation = `${topic}`;

test/strings-test.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ describe('strings', () => {
1010
src: fs.readFileSync(path.resolve(__dirname, '..', 'strings.js'), 'utf-8')
1111
})
1212

13-
it('defines `myString`', () => {
14-
assert.equal(myString, "Hello, world!")
13+
it('defines `greeting`', () => {
14+
assert.equal(greeting, "Hello, everybody!")
1515
})
1616

17-
it('concatenates two strings', () => {
18-
assert.equal(concatenatedString, "A whole is the sum of its parts.")
17+
it('concatenates strings to greet a special guest in `greetSpecialGuest`', () => {
18+
assert.equal(greetSpecialGuest, "Hello, " + specialGuest + "!")
1919
})
2020

21-
it('interpolates a string', () => {
22-
assert.equal(interpolatedString, `I would really like a ${animal}.`)
21+
it('interpolates a string in `conversation`', () => {
22+
assert.equal(conversation, `Let's talk about ${topic}.`)
2323
})
2424
})

0 commit comments

Comments
 (0)