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
112 lines (94 loc) · 2.83 KB
/
app.js
File metadata and controls
112 lines (94 loc) · 2.83 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
console.log("Hello World!\n==========\n");
// Exercise 1 Section
console.log("EXERCISE 1:\n==========\n");
function printOdds(count) {
for (let i = 1; i <= count; i++) {
if (i % 2 != 0) {
console.log(i);
}
}
}
printOdds(10);
printOdds(20);
// Exercise 2 Section
console.log("EXERCISE 2:\n==========\n");
function checkAge(userName, age) {
let aboveSixteen = `Congrats ${userName}, you can drive!`;
let belowSixteen = `Sorry ${userName}, but you need to wait until you're 16.`;
if (age < 16) {
console.log(belowSixteen);
}
else {
console.log(aboveSixteen);
}
}
checkAge("Brandon", 31);
checkAge("Cate", 30);
checkAge("Siena", 7);
// Exercise 3 Section
console.log("EXERCISE 3:\n==========\n");
function quadrant(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";
}
}
console.log(quadrant(3, -4));
console.log(quadrant(-2, 3));
console.log(quadrant(-3, -3));
// Exercise 4 Section
console.log("EXERCISE 4:\n==========\n");
function triangle (one, two, three) {
if (one + two > three && one + three > two && two + three > one) {
if(one == two && two == three) {
return "This is an equilateral triangle.";
}
else if (one == two || two == three || one == three) {
return "This is an isosceles triangle.";
}
else if (one != two && two != three && one != three) {
return "This is a scalene triangle.";
}
}
else {
return "This is an invalid triangle.";
}
}
console.log(triangle(2, 2, 3));
console.log(triangle(5, 5, 5));
console.log(triangle(4, 1, 7));
console.log(triangle(3, 5, 2));
// Exercise 5 Section
console.log("EXERCISE 5:\n==========\n");
function phoneData(planLimit, day, usage) {
let totalDays = 30;
let daysLeft = totalDays - day;
let average = usage / day;
let projectedAvg = planLimit / totalDays;
let remainingData = planLimit - usage;
let projectedUsage = daysLeft * average;
let message;
console.log(`${day} days used, ${daysLeft} days remaning`);
console.log(`Average use daily: ${projectedAvg} GB per day`);
if (average > projectedAvg) {
message = "EXCEEDING";
}
else if (average < projectedAvg) {
message = "UNDER";
}
else {
message = "AT";
}
console.log(`You are ${message} your daily usage of ${average} GB per day.`);
console.log(`If you continue this amount of usage, you will end up using ${planLimit - (usage + projectedUsage)} GB from your max data limit`);
console.log(`In order to keep your data below your limit, do not use more than ${remainingData / daysLeft} GB per day`);
}
phoneData(30, 3, 15);