forked from benrbryant/JavaScript_Functions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
127 lines (107 loc) · 3.75 KB
/
app.js
File metadata and controls
127 lines (107 loc) · 3.75 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
// Exercise 1 Section
// function printOdds(count) {
// for (let i = 1; i <= count; i++) {
// if (i % 2 != 0) {
// console.log(i);
// }
// }
// }
// printOdds(10);
// printOdds(100);
// Exercise 2 Section
// function checkAge (name, age) {
// let aboveEnoughMsg = `Congrats ${name}, you can drive!`;
// let tooYoungMsg = `Sorry ${name}, you need to wait ${16 - age} years(s) until you can drive.`;
// if (age < 16) {
// console.log(tooYoungMsg);
// } else {
// console.log(aboveEnoughMsg);
// }
// }
// checkAge("Tom", 12);
// checkAge("Molly", 25);
// checkAge("Dave", 44);
// Exercise 3
// function checkQuadrant (x, y) {
// if (x > 0 && y > 0) {
// return "Quadrant 1";
// } else if (x < 0 && y > 0) {
// return "Quadrant 2";
// } else if (x < 0 && y < 0) {
// return "Quadrant 3";
// } else if (x > 0 && y < 0) {
// return "Quadrant 4";
// } else if (x == 0 && y != 0) {
// return "X Axis";
// } else if (x != 0 && y == 0) {
// return "Y Axis";
// } else {
// return "Origin";
// }
// }
// console.log(checkQuadrant(1, 1));
// console.log(checkQuadrant(-1, 1));
// console.log(checkQuadrant(-1, -1));
// console.log(checkQuadrant(1, -1));
// console.log(checkQuadrant(0, -1));
// console.log(checkQuadrant(0, 0));
// console.log(checkQuadrant(1, 0));
// Exercise 4
// function isValidTriangle (a, b, c) {
// return (a + b > c && a + c > b && b + c > a);
// // Every two sides must be greater than the third
// }
// function checkTriangle(a, b, c) {
// let isValid = isValidTriangle(a, b, c);
// if (isValid) {
// // What type of triangle?
// if (a == b && b == c) {
// return "Equilateral";
// // If a == b and b == c then a == c by logic
// } else if (a == b || b == c || a == c) {
// return "Isosceles";
// } else {
// return "Scalene";
// }
// } else {
// return "Not a valid triangle.";
// }
// }
// console.log(checkTriangle(2, 3, 4)); // Scalene
// console.log(checkTriangle(2, 2, 2)); // Equilateral
// console.log(checkTriangle(1, 2, 2)); // Isosceles
// console.log(checkTriangle(1, 1, 2)); // Invalid
// Exercise 5
/*
1. 15 days used, 15 days remaining
2. Average daily use: 3.333 GB/day
3. You are EXCEEDING your average daily use (3.73 GB/day),
continuing this high usage, you'll exceed your data plan by
11.9 GB.
To stay below your data plan, use no more than 2.93 GB/day.
*/
function dataUsageFeedback(planLimit, day, usage) {
let periodLength = 30;
let currentAvg = usage / day;
let projectedAvg = planLimit / periodLength; // Using the / divison operator to determine average
let remainingDays = periodLength - day;
let remainingData = planLimit - usage;
let projectedUsage = remainingDays * currentAvg;
let statusMsg; // undefined
if (currentAvg > projectedAvg) {
statusMsg = "EXCEEDING";
} else if (currentAvg < projectedAvg) {
statusMsg = "UNDER";
} else {
statusMsg = "AT";
} // Assigning a string message to statusMsg depending on whether the conditions are true or false
// What you should be able to use per day
// Determines whether you are below, on par, or higher than the above projected use
// A console log that includes string interpolation; intepretes different values and then prints it out
console.log(`${day} day(s) used, ${remainingDays} day(s) remaining.
Average projected use: ${projectedAvg.toFixed(2)} GB/day.
You are ${statusMsg} your average daily use (${currentAvg.toFixed(2)} GB/day),
continuing this high usage, you will end up using ${planLimit - (usage + projectedUsage)} GB from your data limit.
To stay below your data plan, use no more than ${(remainingData / remainingDays).toFixed(2)} GB/day.`);
}
dataUsageFeedback(50, 10, 25); // Calling the function, passing in 3 number parameters