|
1 | 1 |
|
2 |
| -Variables are helpful not only for storing and reusing data but also for simplifying complex calculations. Consider an example: you need to convert euros into yuans through dollars. Banks often do this kind of conversion via an intermediate currency when shopping abroad. |
| 2 | +Variables are helpful not only for storing and reusing data but also for simplifying complex calculations. Consider an example: you need to convert euros into yuan through dollars. Banks often do this kind of conversion via an intermediate currency when shopping abroad. |
3 | 3 |
|
4 | 4 | First, convert 50 euros into dollars. Suppose that one euro is $1.25:
|
5 | 5 |
|
@@ -34,28 +34,28 @@ console.log(who);
|
34 | 34 |
|
35 | 35 | Run it on [repl.it](https://repl.it/languages/javascript) and experiment a little with it.
|
36 | 36 |
|
37 |
| -Now, back to our currency program. We'll record the dollar value in yuans as a separate variable. Calculate the value of 50 euros in dollars by multiplying them by `1.25`. Suppose that 1 dollar is 6.91 yuans: |
| 37 | +Now, back to our currency program. We'll record the dollar value in yuan as a separate variable. Calculate the value of 50 euros in dollars by multiplying them by `1.25`. Suppose that 1 dollar is 6.91 yuan: |
38 | 38 |
|
39 | 39 | ```javascript
|
40 |
| -let yuansPerDollar = 6.91; |
| 40 | +let yuanPerDollar = 6.91; |
41 | 41 | let dollarsCount = 50 * 1.25; // 62.5
|
42 |
| -let yuansCount = dollarsCount * yuansPerDollar; // 431.875 |
| 42 | +let yuanCount = dollarsCount * yuanPerDollar; // 431.875 |
43 | 43 |
|
44 |
| -console.log(yuansCount); |
| 44 | +console.log(yuanCount); |
45 | 45 | ```
|
46 | 46 |
|
47 | 47 | Now, let's merge our output with some text via concatenation:
|
48 | 48 |
|
49 | 49 | ```javascript
|
50 |
| -let yuansPerDollar = 6.91; |
| 50 | +let yuanPerDollar = 6.91; |
51 | 51 | let dollarsCount = 50 * 1.25; // 62.5
|
52 |
| -let yuansCount = dollarsCount * yuansPerDollar; // 431.875 |
| 52 | +let yuanCount = dollarsCount * yuanPerDollar; // 431.875 |
53 | 53 |
|
54 |
| -console.log('The price is ' + yuansCount + ' yuans'); |
| 54 | +console.log('The price is ' + yuanCount + ' yuan'); |
55 | 55 | ```
|
56 | 56 |
|
57 | 57 | <pre class='hexlet-basics-output'>
|
58 |
| -The price is 431.875 yuans |
| 58 | +The price is 431.875 yuan |
59 | 59 | </pre>
|
60 | 60 |
|
61 | 61 | Any variable can be part of any expression. During the computation, the variable's name is replaced with its value.
|
|
0 commit comments