-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path01_node_intro.js
72 lines (46 loc) · 1.54 KB
/
01_node_intro.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
//--- Variable Assignment REPL ---//
// Node does not require var to assign a variable in the REPL
// Assignment
lunch = 'pizza'
// Re-Assignment
lunch = 'fish and chips'
// Strings & Numbers
lunch = '12 inch pizza'
sizeOfParty = 4
totalCost = 14.99
// Math Operations
totalCost / sizeOfParty // 3.7475
// Assignment of math operations to variable
averageCost = totalCost / sizeOfParty
averageCost // 3.7475
// Message
message = 'Your lunch of ' + lunch + ' for ' + sizeOfParty + ' people will cost you ' + averageCost
message
// message = 'Your lunch of 12 inch pizza for 4 people will cost you 3.7475'
//--- Variable Assignment In JS File ---//
// As with all JS files, variable assignment requires var
// Variable Assignment
var lunch = 'pizza';
// Re-Assignment
lunch = 'fish and chips';
// Strings & Numbers
lunch = '12 inch pizza';
var vsizeOfParty = 4;
var totalCost = 14.99;
// Math Operations
console.log(totalCost / sizeOfParty); // 3.7475
// Assignment of math operations to variable
var averageCost = totalCost / sizeOfParty;
console.log(averageCost); // 3.7475
// Message
var message = 'Your lunch of ' + lunch + ' for ' + sizeOfParty + ' people will cost you ' + averageCost;
console.log(message);
// message = 'Your lunch of 12 inch pizza for 4 people will cost you 3.7475'
//--- Bill Calculator Refactor ---//
var totalCost = 14.99;
// Get arguments passed into it when run
var sizeOfParty = process.argv[2];
// Calculate average cost
var averageCost = totalCost / sizeOfParty;
// Console Log Average Cost
console.log("$" + averageCost);