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
105 lines (83 loc) · 3.09 KB
/
app.js
File metadata and controls
105 lines (83 loc) · 3.09 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
console.log("Hello World!\n==========\n");
// Exercise 1 Section
console.log("EXERCISE 1:\n==========\n");
function printOdds(count) {
for (let x = 0; x <= count; x++) {
if (x % 2 !== 0) {
console.log(x);
}
}
}
printOdds(10);
// 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 if (age >= 16) {
console.log(aboveSixteen);
}
}
checkAge("Seth", 16);
// Exercise 3 Section
console.log("EXERCISE 3:\n==========\n");
function quadrant(x1, y1) {
if (y1 === 0 && (x1 > 0 || x1 < 0)) {
console.log(`(${x1}, ${y1}) is on the x axis.`);
} else if (x1 === 0 && (y1 > 0 || y1 < 0)) {
console.log(`(${x1}, ${y1}) is on the y axis.`);
} else if (x1 === 0 && y1 === 0) {
console.log(`(${x1}, ${y1}) is at the origin.`);
} else if (x1 > 0 && y1 > 0) {
console.log(`(${x1}, ${y1}) is in Quadrant 1.`);
} else if (x1 < 0 && y1 > 0) {
console.log(`(${x1}, ${y1}) is in Quadrant 2.`);
} else if (x1 < 0 && y1 < 0) {
console.log(`(${x1}, ${y1}) is in Quadrant 3.`);
} else if (x1 > 0 && y1 < 0) console.log(`(${x1}, ${y1}) is in Quadrant 4.`);
}
quadrant(24, -17);
// Exercise 4 Section
function triangle(a, b, c) {
if (a !== b && a !== c && b === c) {
console.log("Isosceles Triangle.");
} else if (a === b && b === c && a === c) {
console.log("Equilateral Triangle");
} else if (a !== b && b !== c && a !== c) {
console.log("Scalene Trangle");
} else if (a + b <= c) {
console.log("Invalid Triangle.");
}
}
triangle(3, 1, 1);
/* Isosceles: 1, 2, 2 !!!
- Invalid: 1, 1, 2 !!!
Equilateral: 3, 3, 3!!!
Scalene: 1, 2, 3 !!!*/
// Exercise 5 Section
console.log("EXERCISE 5:\n==========\n");
function data(planLimit, day, usage) {
let avgUse = usage / day;
let remData = planLimit - usage;
let daysLeft = 30 - day;
let recUse = planLimit / 30;
let currentRateMax = 30 * avgUse;
let excAmount = currentRateMax - planLimit;
let safeUse = remData / daysLeft;
if (currentRateMax > planLimit) {
console.log(
`Recommended Average daily use: ${recUse}GB/day. You are EXCEEDING your recommended average use (currently ${avgUse}GB/day). Continuing this high usage, you will exceed your data plan by ${excAmount}GB. To stay below your data plan, use no more than ${safeUse}GB/day.`
);
} else if (currentRateMax < planLimit) {
console.log(
`Recommended Average daily use: ${recUse}GB/day. You are below your recommended average use (currently ${avgUse}GB/day). Continuing this low usage, you will lose ${remData} GB of unused data. To ensure you are able to take advantage of your remaining data, use at least ${safeUse}GB/day.`
);
} else if (currentRateMax == planLimit) {
console.log(
`Your current average daily use, ${recUse}GB/day, is the same as your recommended data usage. Continuing to use data at this rate will make full use of the data in your plan.`
);
}
return;
}