@@ -21,15 +21,15 @@ In the first tutorial, we learnt all about **values**.
2121``` js
2222const name = ' codebar' ;
2323
24- console .log (name + ' is amazing!' ); // this is an expression
24+ console .log (` ${ name} is amazing!` ); // this is an expression
2525```
2626
2727** Numbers** :
2828
2929``` js
3030const pi = 3.14 ;
3131
32- console .log (' The value of pi: ' + pi );
32+ console .log (` The value of pi: ${ pi } ` );
3333```
3434
3535and ** Objects** :
@@ -39,7 +39,7 @@ const person = {
3939 first_name: ' Archibald'
4040};
4141
42- console .log (' Hello ' + person .first_name + ' ! ' );
42+ console .log (` Hello ${ person .first_name } ! ` );
4343```
4444
4545We are now going to introduce one more important type: ** booleans** . A
@@ -49,8 +49,8 @@ boolean can only be `true` or `false`, for example:
4949const codebarIsAwesome = true ;
5050const weatherIsAmazing = false ;
5151
52- console .log (' Is codebar AWESOME? ' + codebarIsAwesome);
53- console .log (' Is the weather in London amazing? ' + weatherIsAmazing);
52+ console .log (` Is codebar AWESOME? ${ codebarIsAwesome} ` );
53+ console .log (` Is the weather in London amazing? ${ weatherIsAmazing} ` );
5454```
5555
5656## Expressions
@@ -65,19 +65,19 @@ const x = 6;
6565const y = 3 ;
6666const addition = x + y;
6767
68- console .log (' Addition: x + y = ' + addition); // Addition: x + y = 9
68+ console .log (` Addition: x + y = ${ addition} ` ); // Addition: x + y = 9
6969
7070const subtraction = x - y;
7171
72- console .log (' Subtraction: x - y = ' + subtraction); // Subtraction: x - y = 3
72+ console .log (` Subtraction: x - y = ${ subtraction} ` ); // Subtraction: x - y = 3
7373
7474const multiplication = x * y;
7575
76- console .log (' Multiplication: x * y = ' + multiplication); // Multiplication: x * y = 18
76+ console .log (` Multiplication: x * y = ${ multiplication} ` ); // Multiplication: x * y = 18
7777
7878const division = x / y;
7979
80- console .log (' Division: x / y = ' + division); // Division: x / y = 2
80+ console .log (` Division: x / y = ${ division} ` ); // Division: x / y = 2
8181```
8282
8383> Why not try some other maths problem using the ` x ` and ` y ` variables?
@@ -97,19 +97,19 @@ let x = 5;
9797let y = 3 ;
9898const modulus = x % y;
9999
100- console .log (' Remainder: x % y = ' + modulus);
100+ console .log (` Remainder: x % y = ${ modulus} ` );
101101
102102const exponentiation = x ** y;
103103
104- console .log (' Exponentiation: x ** y = ' + exponentiation);
104+ console .log (` Exponentiation: x ** y = ${ exponentiation} ` );
105105
106106const increment = x++ ;
107107
108- console .log (' Increment: x++ = ' + increment);
108+ console .log (` Increment: x++ = ${ increment} ` );
109109
110110const decrement = y-- ;
111111
112- console .log (' Decrement: y-- = ' + decrement);
112+ console .log (` Decrement: y-- = ${ decrement} ` );
113113```
114114
115115#### Comparisons
@@ -122,7 +122,7 @@ const oranges = 'oranges';
122122
123123const equal = apples === oranges;
124124
125- console .log (' Apples and oranges are the exactly same: ' + equal);
125+ console .log (` Apples and oranges are the exactly same: ${ equal} ` );
126126```
127127
128128The opposite of ` === ` is ` !== ` . It returns ` true ` if they are not equal, and ` false ` if they are.
@@ -133,7 +133,7 @@ const oranges = 'oranges';
133133
134134const notEqual = apples !== oranges;
135135
136- console .log (' Apples and oranges are different: ' + notEqual);
136+ console .log (` Apples and oranges are different: ${ notEqual} ` );
137137```
138138
139139> You may also see ` == ` and ` != ` , these are similar but have some quirks so it's generally recommended to avoid them.
@@ -148,10 +148,10 @@ const students = 24;
148148const pizzas = 25 ;
149149
150150const moreStudents = students > coaches;
151- console .log (' Are there more students than coaches?' + moreStudents);
151+ console .log (` Are there more students than coaches? ${ moreStudents} ` );
152152
153153const lessStudents = students < pizzas;
154- console .log (' Are there fewer students than pizzas?' + lessStudents);
154+ console .log (` Are there fewer students than pizzas? ${ lessStudents} ` );
155155
156156```
157157> Play around with changing the ` coaches ` , ` students ` and ` pizzas ` variable numbers to familiarise yourself with operators.
@@ -160,7 +160,7 @@ You can also combine operators.
160160
161161``` js
162162const enoughPizzas = (coaches + students) < pizzas;
163- console .log (' Do we have enough pizzas for everybody? ' + enoughPizzas);
163+ console .log (` Do we have enough pizzas for everybody? ${ enoughPizzas} ` );
164164```
165165> Now sit with your coach and create 2 variables, one is your age and one is the
166166> minimum driving age. Then console log whether you are old enough to drive.
@@ -256,7 +256,7 @@ while (i <= 10) {
256256 i = i + 1 ;
257257}
258258
259- console .log (' Total: ' + total);
259+ console .log (` Total: ${ total} ` );
260260```
261261
262262> We can also express ` <= 10 ` using ` < 11 `
@@ -299,7 +299,7 @@ for (i = 1; i <= 10; i = i + 1) {
299299 total = total + i;
300300}
301301
302- console .log (' Total: ' + total);
302+ console .log (` Total: ${ total} ` );
303303```
304304> Another way to write the for loop is ` for (let i = 1; i <= 10; i++) ` . The ` i++ ` is a short way of writing "increase i by one".
305305
@@ -577,7 +577,7 @@ function displayPopulation() {
577577 const paragraph = document .createElement (' p' );
578578
579579 // Make some text content to put into your <p></p>
580- const content = document .createTextNode (' Population: ' + london .population );
580+ const content = document .createTextNode (` Population: ${ london .population } ` );
581581
582582 // Put the text content into the <p></p>.
583583 paragraph .appendChild (content);
0 commit comments