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
209 lines (190 loc) · 5.44 KB
/
app.js
File metadata and controls
209 lines (190 loc) · 5.44 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
console.log("Hello World!\n==========\n");
// Exercise 1 Section
console.log("EXERCISE 1:\n== Print Odds/ Minimum Number======\n");
function printtodds(count)
{
// This works without the bonues
//for ( let i = 1; i <= count ; i++)
//{
//if (i %2 != 0)
//{
// console.log(i);
//}
if (count < 0)
{
// Bonus to account for negative count
for (let i = -1; i >= count; i--)
{
if (i % 2 !=0)
{
console.log(i);
}
}
}
else
{
// account for positive number
for (let i = 1; i <= count; i++)
{
if (i % 2 != 0)
{
console.log(i);
}
}
}
}
printtodds(-10);
printtodds(10);
// Exercise 2 Section
console.log("\n==========\n");
console.log("EXERCISE 2:\n==Legal?=======\n");
let _name;
let age;
function checkAge(_name, age)
{
let oldEnoughMsg = `Congrats ${_name}! You are ${age} can drive!`;
let tooYoungMsg = `Sorry ${_name}, but you are ${age} and you need to wait until you're 16.`;
if (age < 16)
{
console.log(tooYoungMsg);
}
else
{
console.log(oldEnoughMsg);
}
}
checkAge("Myriam",18);
checkAge("Nancy",12);
checkAge("Ben",21);
// Exercise 3: Which Quadrant?Section
console.log("\n==========\n");
console.log("Exercise 3: :\n==Which Quadrant?=======\n");
function checkQuandrant(x,y)
{
let quandrant;
if (x >0 && y >0)
{
//return "Quadrant1";
console.log("Quadrant1");
console.log(`X is ${x} and Y is ${y}\n`);
console.log("------------");
} else if (x < 0 && y >0)
{
console.log("Quadrant2");
console.log(`X is ${x} and Y is ${y}\n`);
console.log("------------");
} else if (x < 0 && y < 0 )
{
console.log("Quadrant3");
console.log(`X is ${x} and Y is ${y}\n`);
console.log("------------");
} else if ( x >0 && y < 0)
{
console.log( "Quadrant4");
console.log(`X is ${x} and Y is ${y}\n`);
console.log("------------");
} else if ( x==0 && y !=0)
{
console.log("X Axis");
console.log(`X is ${x} and Y is ${y}\n`);
console.log("------------");
}else if (x != 0 && y ==0)
{
console.log("Y Axis");
console.log(`X is ${x} and Y is ${y}\n`);
console.log("------------");
} else
{
console.log( "both x and y are zero");
console.log(`X is ${x} and Y is ${y}\n`);
console.log("------------");
}
}
checkQuandrant(5,5);
checkQuandrant(-5,5);
checkQuandrant(-5,-5);
checkQuandrant(5,-5);
checkQuandrant(0,5);
checkQuandrant(5,0);
checkQuandrant(0,0);
// Exercise 4 Section
console.log("\n==========\n");
console.log("EXERCISE 4:\n==What type of triangle?=======\n");
//First Need to check if the shape is a Triangle
function isValidTriangle(a,b,c)
{
return a + b > c && a + c >b && b +c > a;
}
function checkTriangle(a ,b, c)
{
let Valid = isValidTriangle(a, b, c);
if (Valid)
{
if (a == b && b == c)
{
return "The Triamgle is Equilateral";
}
else if (a == b || b == c || a == c)
{
return "The Triamgle is Isoceles";
}
else ( a == b )
{
return "The Triamgle is Scalene";
}
}
else
{
return "Not a valid triangle";
}
}
console.log(checkTriangle(2,2,2)); // Equilateral
console.log(checkTriangle(1,2,2)); // Isoceles
console.log(checkTriangle(2,3,4)); // Scalene
console.log(checkTriangle(1,1,2)); // not Valid
// Exercise 5 Section
console.log("\n==========\n");
console.log("EXERCISE 5:\n==Data Plan Status?=======\n");
/* planlimit , day, usage
```txt
`planLimit = 100`, `day = 15`, and `usage = 56`,
15 days used, 15 days remaining
Average daily use: 3.333 GB/day
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 dataUsage(planLimit, day, usage)
{
let periodLength = 30;
let currentAvg = usage/day;
let projectedAvg = planLimit/periodLength;
let remainingData = planLimit - usage;
let remainingDays = periodLength - day;
let projectedUsage = remainingDays * currentAvg;
let statusMsg;
if (currentAvg > projectedAvg)
{
statusMsg = "EXCEEDING";
}
else if (currentAvg < projectedAvg)
{
statusMsg = "UNDER";
}
else
{
statusMsg = "AT";
}
console.log(`The Plan limit is: ${planLimit}. The Days used: ${day} day(s) used. The usage is: ${usage}`);
console.log(`${day} day(s) used, ${remainingDays} day(s) remaining`);
console.log(`Average projected use: ${projectedAvg} GB/day`);
console.log(`You are ${statusMsg} your average daily use (${currentAvg}GB/day),`);
console.log(`continuing this high usage, you'll end up using ${(usage + projectedUsage)- planLimit} GB from your data limit.`);
console.log(`To stay below your data plan, use no more than ${remainingData/remainingDays} GB/day.`);
console.log(`=============================================================`);
}
dataUsage(100, 15, 56);
dataUsage(50, 12, 25);
dataUsage(50, 15, 25);
dataUsage(50, 10, 25);