Skip to content

Commit eb88316

Browse files
committed
another round of changes from code review
1 parent e961b98 commit eb88316

File tree

9 files changed

+34
-16
lines changed

9 files changed

+34
-16
lines changed

concepts/template-strings/about.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
# About
1+
# Introduction
22

33
In JavaScript, _template strings_ allows for embedding expressions in strings, also referred to as string interpolation.
44
This functionality extends the functionality of the built in [`String`][string-reference] global object.
55

6-
You can create template strings in javascript by wrapping text in backticks.
6+
You can create template strings in JavaScript by wrapping text in backticks.
77
They not only allow the text to include new lines and other special characters, you can also embed variables and other expressions.
88

99
```javascript
@@ -34,6 +34,10 @@ strings to accomplish multiple
3434
lines`;
3535
```
3636

37+
With the substitution capabilities that are available, you can also introduce logic into the process to determine what the output string should be.
38+
One way to handle the logic could be using the [ternary operator][ternary-operator].
39+
This gives the same conditional `if/else` functionality in a slightly different format.
40+
3741
To implement logic into template string syntax:
3842

3943
```javascript
@@ -45,3 +49,4 @@ const grade = 95;
4549

4650
[string-reference]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String
4751
[type-conversion-concept]: /tracks/javascript/concepts/type-conversion
52+
[ternary-operator]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Conditional_Operator

concepts/template-strings/introduction.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
In JavaScript, _template strings_ allows for embedding expressions in strings, also referred to as string interpolation.
44
This functionality extends the functionality of the built in [`String`][string-reference] global object.
55

6-
You can create template strings in javascript by wrapping text in backticks.
6+
You can create template strings in JavaScript by wrapping text in backticks.
77
They not only allow the text to include new lines and other special characters, you can also embed variables and other expressions.
88

99
```javascript
@@ -34,6 +34,10 @@ strings to accomplish multiple
3434
lines`;
3535
```
3636

37+
With the substitution capabilities that are available, you can also introduce logic into the process to determine what the output string should be.
38+
One way to handle the logic could be using the [ternary operator][ternary-operator].
39+
This gives the same conditional `if/else` functionality in a slightly different format.
40+
3741
To implement logic into template string syntax:
3842

3943
```javascript
@@ -45,3 +49,4 @@ const grade = 95;
4549

4650
[string-reference]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String
4751
[type-conversion-concept]: /tracks/javascript/concepts/type-conversion
52+
[ternary-operator]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Conditional_Operator

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,11 @@
1515

1616
## 5. Compute the cost of a sign
1717

18-
- Figure out the [`length`][mdn-string-length] of the characters that can be _parsed_ and return a _floating point_ number.
19-
- Once you have the [floating point][mdn-parse-float] number, you will need to set it to only show the first two numbers using [fixed-point][mdn-to-fixed] notation.
18+
- Figure out the [`length`][mdn-string-length] of the characters.
19+
- Only show the first two decimal numbers using [fixed-point][mdn-to-fixed] notation.
2020

2121
[mdn-const]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/const
2222
[mdn-template-strings]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals
2323
[mdn-string-length]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/length
24-
[mdn-parse-float]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseFloat
2524
[mdn-to-fixed]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toFixed
2625
[mdn-ternary-operator]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Conditional_Operator

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ graduationFor('Hannah', 2022);
3434

3535
## 5. Compute the cost of a sign
3636

37-
Implement the function `costOf(sign, currency)` which takes a string that holds the contents of the sign and a string that represents the currency and returns a phrase that includes the cost to create the sign, formatted with a fixed point notation set to 2 points, followed by the currency string.
37+
Implement the function `costOf(sign, currency)` which takes a string that holds the contents of the sign and a string that represents the currency.
38+
The cost is calculated based on each letter in the sign costing two dollars with an additional 20 dollars for the sign created.
39+
The phrase returned includes the cost to create the sign, formatted with a fixed point notation set to 2 points, followed by the currency string.
3840

3941
```javascript
4042
costOf('Congratulations Rob Class of 2021', 'dollars');

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
In JavaScript, _template strings_ allows for embedding expressions in strings, also referred to as string interpolation.
44
This functionality extends the functionality of the built in [`String`][string-reference] global object.
55

6-
You can create template strings in javascript by wrapping text in backticks.
6+
You can create template strings in JavaScript by wrapping text in backticks.
77
They not only allow the text to include new lines and other special characters, you can also embed variables and other expressions.
88

99
```javascript
@@ -34,6 +34,10 @@ strings to accomplish multiple
3434
lines`;
3535
```
3636

37+
With the substitution capabilities that are available, you can also introduce logic into the process to determine what the output string should be.
38+
One way to handle the logic could be using the [ternary operator][ternary-operator].
39+
This gives the same conditional `if/else` functionality in a slightly different format.
40+
3741
To implement logic into template string syntax:
3842

3943
```javascript
@@ -45,3 +49,4 @@ const grade = 95;
4549

4650
[string-reference]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String
4751
[type-conversion-concept]: /tracks/javascript/concepts/type-conversion
52+
[ternary-operator]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Conditional_Operator

exercises/concept/custom-signs/.meta/config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"blurb": "Learn about characters by helping a sign company create custom messages for their signs.",
2+
"blurb": "Learn about template strings and the ternary operator ...",
33
"authors": ["pertrai1"],
44
"contributors": [],
55
"files": {

exercises/concept/custom-signs/.meta/exemplar.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,5 @@ export function graduationFor(name, year) {
1616
}
1717

1818
export function costOf(sign, currency = 'dollars') {
19-
const convertedSign = Number.parseFloat(sign.length);
20-
return `Your sign cost ${(convertedSign * 2 + 20).toFixed(2)} ${currency}`;
19+
return `Your sign cost ${(sign.length * 2 + 20).toFixed(2)} ${currency}`;
2120
}

exercises/concept/custom-signs/custom-signs.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// implementing this exercise.
66

77
/**
8-
* Build a string that includes both of the parameters.
8+
* Build a sign that includes both of the parameters.
99
*
1010
* @param {string} occasion
1111
* @param {string} name
@@ -18,7 +18,7 @@ export function buildSign(occasion, name) {
1818
}
1919

2020
/**
21-
* Build a string that conditionally formats the return string.
21+
* Build a birthday sign that conditionally formats the return string.
2222
*
2323
* @param {number} age
2424
*
@@ -30,7 +30,7 @@ export function buildBirthdaySign(age) {
3030
}
3131

3232
/**
33-
* Build a string formatted on multiple lines.
33+
* Build a graduation sign that includes multiple lines.
3434
*
3535
* @param {string} name
3636
* @param {number} year
@@ -49,7 +49,7 @@ export function graduationFor(name, year) {
4949
* @param {string} sign
5050
* @param {string} currency
5151
*
52-
* @returns {number} cost to create the sign
52+
* @returns {string} cost to create the sign
5353
*/
5454

5555
export function costOf(sign, currency) {

exercises/concept/custom-signs/custom-signs.spec.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ import {
99

1010
describe('buildSign', () => {
1111
test('occasion is Birthday', () => {
12-
expect(buildSign('Birthday', 'Rob')).toBe('Happy Birthday Rob!');
12+
expect(buildSign('Birthday', 'Jack')).toBe('Happy Birthday Jack!');
13+
});
14+
test('occasion is Anniversary', () => {
15+
expect(buildSign('Anniversary', 'Jill')).toBe('Happy Anniversary Jill!');
1316
});
1417
});
1518

0 commit comments

Comments
 (0)