Skip to content

Commit 59d4935

Browse files
committed
template strings lesson done
1 parent 6e17a26 commit 59d4935

File tree

1 file changed

+30
-23
lines changed

1 file changed

+30
-23
lines changed

app/index.js

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,38 @@
1-
// var name = "Jane";
2-
// var title = "Software Engineer";
3-
// var hourlyWage = 40;
1+
//Template Strings
42

5-
//ES6
3+
function getMessage() {
4+
const year = new Date().getFullYear();
5+
return "The year is " + year;
6+
}
67

7-
// const is used because we don't expect the name to change
8-
//let is used when we expect the variable to change, it is more similar to var
9-
const name = "Jane";
10-
let title = "Software Engineer";
11-
let hourlyWage = 40;
8+
console.log(getMessage());
129

13-
// some time later...
1410

15-
title = 'Senior Software Engineer';
16-
hourlyWage = 45;
11+
// difference is we use back ticks and then whereever we want a variable to appear we put it inside of the
12+
// ${variableNameHere}. This allows us to not have to use normal concatenation.
13+
// inside the ${} you don't just have to have a variable, you can do any JS expression so you can do math for
14+
//instance
15+
function getMessage() {
16+
const year = new Date().getFullYear();
17+
return `The year is ${year}`;
18+
}
1719

20+
console.log(getMessage());
1821

19-
function count (string) {
20-
const characters = ['a', 'e', 'i', 'o', 'u'];
21-
let number = 0;
22+
//PHP
23+
// $data = '{"device_id":"'.$device_id.'","guid":"'.$guid.'","username":"'.$username.'","}';
2224

23-
for (let i = 0; i < string.length; i++) {
24-
if (characters.includes(string[i])) {
25-
number++
26-
}
27-
}
28-
return number;
29-
}
25+
data = '{"device_id":"' + device_id +'", "guid":"' + guid +'", "username":"' + username +'","}';
3026

31-
console.log(count('aeiobzxceiaipbiox'));
27+
data = `{"device_id": "${device_id}", "guid": "${guid}", "username": "${username}", "} `;
28+
29+
30+
//don't do the following
31+
const year = 2016;
32+
const yearMsg = `${year}`;
33+
yearMsg;
34+
35+
//should just be
36+
const year = 2016;
37+
const yearMsg = year;
38+
yearMsg;

0 commit comments

Comments
 (0)