Skip to content

Commit 3a5f9ae

Browse files
FFFF-0000hSleeplessBytegithub-actions[bot]
authored
Enhance template string lesson with newline escape sequence demonstration (#2776)
* Update introduction.md * Update instructions.md * Update concepts/template-strings/introduction.md Co-authored-by: Derk-Jan Karrenbeld <[email protected]> * [CI] Format code --------- Co-authored-by: Derk-Jan Karrenbeld <[email protected]> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent a5bd153 commit 3a5f9ae

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

concepts/template-strings/introduction.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,22 @@ When you are needing to have strings formatted on multiple lines:
3232
`This is an example of using template
3333
strings to accomplish multiple
3434
lines`;
35+
36+
/* => This is an example of using template
37+
strings to accomplish multiple
38+
lines
39+
*/
3540
```
3641

42+
If you want to represent a newline inside a regular string instead of using a template string (ie. not using backticks), you can use the newline escape sequence `\n`:
43+
44+
````javascript
45+
"This is an example of using the newline escape sequence!\nWithout backticks"
46+
47+
/* => This is an example of using the newline escape sequence!
48+
Without backticks
49+
*/
50+
3751
With the available substitution capabilities, you can also introduce logic into the process to determine what the output string should be.
3852
One way to handle the logic could be using the [ternary operator][ternary-operator].
3953
This gives the same conditional `if/else` functionality in a slightly different format.
@@ -45,7 +59,7 @@ const grade = 95;
4559
4660
`You have ${grade > 90 ? 'passed' : 'failed'} the exam.`;
4761
// => You have passed the exam.
48-
```
62+
````
4963
5064
[string-reference]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String
5165
[type-conversion-concept]: /tracks/javascript/concepts/type-conversion

exercises/concept/custom-signs/.docs/instructions.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ Implement the function `graduationFor(name, year)` which takes a name as a strin
3232

3333
```javascript
3434
graduationFor('Hannah', 2022);
35-
// => "Congratulations Hannah!\nClass of 2022"
35+
/* => "Congratulations Hannah!
36+
Class of 2022"
37+
*/
3638
```
3739

3840
## 4. Compute the cost of a sign

0 commit comments

Comments
 (0)