Skip to content

Commit

Permalink
template literals second pass
Browse files Browse the repository at this point in the history
  • Loading branch information
josephmaxwellhyland committed Jan 25, 2021
1 parent a0e9e3c commit 6f8f6c3
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
5 changes: 2 additions & 3 deletions TemplateLiterals/DriversLicenseCodeAlong.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ if (age > 16) {
## Template Literals
Now it's finally time to learn about [template literals](https://flaviocopes.com/javascript-template-literals/)! Looking at the string printing code right now, it's a little messy. Using **template literals** can help clean them up a lot.

Template Literals are a lot like normal strings, but instead of quotes or double quotes, they use _backticks_ (`\``). They also allow for multi-line strings, and string interpolation. Replace the existing strings with template strings to see how much simpler they make things!
Template Literals are a lot like normal strings, but instead of quotes or double quotes, they use _backticks_ (`). They also allow for multi-line strings, and string interpolation. Replace the existing strings with template strings to see how much simpler they make things!

### Interpolation
The first step is to use _interpolation_. This allows developers to easily place expressions or values within strings, without having to use `+` to concatenate multiple things together! Imagine an example like this:
Expand All @@ -160,7 +160,7 @@ Interpolated values begin with `${` and end with `}`. Everything within will be

Update the code so that it uses template literals instead of normal strings!

1. Replace the quotes `'` with backticks `\`` for each line
1. Replace the quotes (`'`) with backticks (`) for each line
1. Remove the `+` and extra strings, so each line is back to being one string
1. Use `${name}` to insert the `name` value
1. Do the same for `${age}` and `${donor}`
Expand Down Expand Up @@ -211,7 +211,6 @@ Run the program again, and verify that it still works as expected!
`;
```

### Note
Ultimately, using template literals makes things much easier to scale and maintain. They will come in handy when working with strings in almost any situation!

## Final Code
Expand Down
2 changes: 1 addition & 1 deletion TemplateLiterals/DriversLicenseIndividualExercises.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ Create a piece of customizable birthday cake ASCII Art. It should be able to pla
1. In the body of the function, check if the `name` is short enough
- If it is not, print a message and return
1. Pad the name an appropriate amount so that it appears in the middle of the cake
- e.g., `Homer Simpson` should become ` Homer Simpson `
- e.g., `Homer Simpson` should add three spaces on the left, and three on the right
1. Create a template literal containing the cake ASCII
1. Place the padded name in the proper spot within the string
1. Print the string to the console
Expand Down
4 changes: 2 additions & 2 deletions TemplateLiterals/StudentDesc.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Use Node.js to create a console app, and learn how to use template literals to work more efficiently with strings. Complete the **Driver's License Code-Along Activity**, and then work on the **Driver's License Individual Exercises**.

## Driver's License Code-Along Activity
Follow the instructions on [this page](SimpleServerCodeAlong.md) to create a Node.js application that displays some driver's license information.
Follow the instructions on [this page](DriversLicenseCodeAlong.md) to create a Node.js application that displays some driver's license information.

## Driver's License Individual Exercises
After completing the code-along activity, complete the exercises on [this page](SimpleServerIndividualExercises.md) to build on the driver's license app.
After completing the code-along activity, complete the exercises on [this page](DriversLicenseIndividualExercises.md) to build on the driver's license app.

0 comments on commit 6f8f6c3

Please sign in to comment.