|
| 1 | +--- |
| 2 | +id: 66c057041df6394ca796bf33 |
| 3 | +title: Build a Sentence Maker |
| 4 | +challengeType: 14 |
| 5 | +dashedName: build-a-sentence-maker |
| 6 | +--- |
| 7 | + |
| 8 | +# --description-- |
| 9 | + |
| 10 | +In this lab, you will create two different stories using a sentence template. You will use variables to store different parts of the story and then output the stories to the console. |
| 11 | + |
| 12 | +**Objective:** Fulfill the user stories below and get all the tests to pass to complete the lab. |
| 13 | + |
| 14 | +**User Stories:** |
| 15 | + |
| 16 | +1. You should declare the following variables using `let`: |
| 17 | + |
| 18 | +- `adjective` |
| 19 | +- `noun` |
| 20 | +- `verb` |
| 21 | +- `place` |
| 22 | +- `adjective2` |
| 23 | +- `noun2` |
| 24 | + |
| 25 | +1. You should assign the above variables some string values of your choice. |
| 26 | + |
| 27 | +2. You should declare a `firstStory` variable using `const` to store the first story. |
| 28 | + |
| 29 | +3. You should use the following story template to create the first story and assign it to the `firstStory` variable: |
| 30 | + |
| 31 | +`"Once upon a time, there was a(n) [adjective] [noun] who loved to eat [noun2]. The [noun] lived in a [place] and had [adjective2] nostrils that blew fire when it was [verb]."`; |
| 32 | + |
| 33 | +1. You should output your first story to the console using the message `"First story: [firstStory]"`. |
| 34 | + |
| 35 | +1. You should assign new values to your `adjective`, `noun`, `verb`, `place`, `adjective2`, and `noun2` variables. |
| 36 | + |
| 37 | +1. Create another story using the same template and assign it to the `secondStory` variable. |
| 38 | + |
| 39 | +1. You should output your second story to the console using the message `"Second story: [secondStory]"`. |
| 40 | + |
| 41 | + |
| 42 | +# --hints-- |
| 43 | + |
| 44 | +You should declare an `adjective` variable. |
| 45 | + |
| 46 | +```js |
| 47 | +assert.isNotNull(adjective); |
| 48 | +``` |
| 49 | + |
| 50 | +You should declare a `noun` variable. |
| 51 | + |
| 52 | +```js |
| 53 | +assert.isNotNull(noun); |
| 54 | +``` |
| 55 | + |
| 56 | +You should declare a `verb` variable. |
| 57 | + |
| 58 | +```js |
| 59 | +assert.isNotNull(verb); |
| 60 | +``` |
| 61 | + |
| 62 | +You should declare a `place` variable. |
| 63 | + |
| 64 | +```js |
| 65 | +assert.isNotNull(place); |
| 66 | +``` |
| 67 | + |
| 68 | +You should declare an `adjective2` variable. |
| 69 | + |
| 70 | +```js |
| 71 | +assert.isNotNull(adjective2); |
| 72 | +``` |
| 73 | + |
| 74 | +You should declare a `noun2` variable. |
| 75 | + |
| 76 | +```js |
| 77 | +assert.isNotNull(noun2); |
| 78 | +``` |
| 79 | + |
| 80 | +You should assign a string value to the `adjective` variable. |
| 81 | + |
| 82 | +```js |
| 83 | +assert.isString(adjective); |
| 84 | +``` |
| 85 | + |
| 86 | +You should assign a string value to the `noun` variable. |
| 87 | + |
| 88 | +```js |
| 89 | +assert.isString(noun); |
| 90 | +``` |
| 91 | + |
| 92 | +You should assign a string value to the `verb` variable. |
| 93 | + |
| 94 | +```js |
| 95 | +assert.isString(verb); |
| 96 | +``` |
| 97 | + |
| 98 | +You should assign a string value to the `place` variable. |
| 99 | + |
| 100 | +```js |
| 101 | +assert.isString(place); |
| 102 | +``` |
| 103 | + |
| 104 | +You should assign a string value to the `adjective2` variable. |
| 105 | + |
| 106 | +```js |
| 107 | +assert.isString(adjective2); |
| 108 | +``` |
| 109 | + |
| 110 | +You should assign a string value to the `noun2` variable. |
| 111 | + |
| 112 | +```js |
| 113 | +assert.isString(noun2); |
| 114 | +``` |
| 115 | + |
| 116 | +You should declare a `firstStory` variable. |
| 117 | + |
| 118 | +```js |
| 119 | +assert.isNotNull(firstStory); |
| 120 | +``` |
| 121 | + |
| 122 | +Your should use the correct story format for both stories: `"Once upon a time, there was a(n) [adjective] [noun] who loved to eat [noun2]. The [noun] lived in a [place] and had [adjective2] nostrils that blew fire when it was [verb]."`. Pay attention to spaces. |
| 123 | + |
| 124 | +```js |
| 125 | +const expected = `Once upon a time, there was a(n) ${adjective} ${noun} who loved to eat ${noun2}. The ${noun} lived in a ${place} and had ${adjective2} nostrils that blew fire when it was ${verb}.`; |
| 126 | +assert.strictEqual(secondStory, expected); |
| 127 | +``` |
| 128 | + |
| 129 | +You should log your first story using the message `"First story: [firstStory]"`. |
| 130 | + |
| 131 | +```js |
| 132 | +const condition1 = /console\.log\(\s*["']First\s+story:\s+["']\s*\+\s*firstStory\s*\);?/gm.test(code); |
| 133 | +const condition2 = /console\.log\(\s*`First\s+story:\s+\$\{firstStory\}`\s*\);?/gm.test(code); |
| 134 | +assert.isTrue(condition1 || condition2); |
| 135 | +``` |
| 136 | + |
| 137 | +You should declare a `secondStory` variable. |
| 138 | + |
| 139 | +```js |
| 140 | +assert.isNotNull(secondStory); |
| 141 | +``` |
| 142 | + |
| 143 | +You should reassign the `adjective` variable for the second story. |
| 144 | + |
| 145 | +```js |
| 146 | +assert.lengthOf(__helpers.removeJSComments(code).match(/adjective\s*=\s*/g), 2); |
| 147 | +``` |
| 148 | + |
| 149 | +You should reassign the `noun` variable for the second story. |
| 150 | + |
| 151 | +```js |
| 152 | +assert.lengthOf(__helpers.removeJSComments(code).match(/noun\s*=\s*/g), 2); |
| 153 | +``` |
| 154 | + |
| 155 | +You should reassign the `verb` variable for the second story. |
| 156 | + |
| 157 | +```js |
| 158 | +assert.lengthOf(__helpers.removeJSComments(code).match(/verb\s*=\s*/g), 2); |
| 159 | +``` |
| 160 | + |
| 161 | +You should reassign the `place` variable for the second story. |
| 162 | + |
| 163 | +```js |
| 164 | +assert.lengthOf(__helpers.removeJSComments(code).match(/place\s*=\s*/g), 2); |
| 165 | +``` |
| 166 | + |
| 167 | +You should reassign the `adjective2` variable for the second story. |
| 168 | + |
| 169 | +```js |
| 170 | +assert.lengthOf(__helpers.removeJSComments(code).match(/adjective2\s*=\s*/g), 2); |
| 171 | +``` |
| 172 | + |
| 173 | +You should reassign the `noun2` variable for the second story. |
| 174 | + |
| 175 | +```js |
| 176 | +assert.lengthOf(__helpers.removeJSComments(code).match(/noun2\s*=\s*/g), 2); |
| 177 | +``` |
| 178 | + |
| 179 | +You should log your second story using the format `"Second story: [secondStory]"`. |
| 180 | + |
| 181 | +```js |
| 182 | +const condition1 = /console\.log\(\s*["']Second\s+story:\s+["']\s*\+\s*secondStory\s*\);?/gm.test(code); |
| 183 | +const condition2 = /console\.log\(\s*`Second\s+story:\s+\$\{secondStory\}`\s*\);?/gm.test(code); |
| 184 | +assert.isTrue(condition1 || condition2); |
| 185 | +``` |
| 186 | + |
| 187 | +The `firstStory` should not be the same as the `secondStory`. |
| 188 | + |
| 189 | +```js |
| 190 | +assert.notEqual(firstStory, secondStory); |
| 191 | +``` |
| 192 | + |
| 193 | +# --seed-- |
| 194 | + |
| 195 | +## --seed-contents-- |
| 196 | + |
| 197 | +```js |
| 198 | + |
| 199 | +``` |
| 200 | + |
| 201 | +# --solutions-- |
| 202 | + |
| 203 | +```js |
| 204 | +let adjective = "funny"; |
| 205 | +let noun = "dragon"; |
| 206 | +let verb = "jumping"; |
| 207 | +let place = "garden"; |
| 208 | +let adjective2 = "sparkling"; |
| 209 | +let noun2 = "cakes"; |
| 210 | + |
| 211 | +const firstStory = `Once upon a time, there was a(n) ${adjective} ${noun} who loved to eat ${noun2}. The ${noun} lived in a ${place} and had ${adjective2} nostrils that blew fire when it was ${verb}.`; |
| 212 | + |
| 213 | +console.log("First story: " + firstStory); |
| 214 | + |
| 215 | +adjective = "cute"; |
| 216 | +noun = "puppy"; |
| 217 | +verb = "barking"; |
| 218 | +place = "park"; |
| 219 | +adjective2 = "colorful"; |
| 220 | +noun2 = "flower"; |
| 221 | + |
| 222 | +const secondStory = `Once upon a time, there was a(n) ${adjective} ${noun} who loved to eat ${noun2}. The ${noun} lived in a ${place} and had ${adjective2} nostrils that blew fire when it was ${verb}.`; |
| 223 | + |
| 224 | +console.log("Second story: " + secondStory); |
| 225 | +``` |
| 226 | + |
0 commit comments