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
99 lines (84 loc) · 2.82 KB
/
app.js
File metadata and controls
99 lines (84 loc) · 2.82 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
console.log("Hello World!\n==========\n");
// Exercise 1 Section
console.log("EXERCISE 1:\n==========\n");
function printOdds(count) {
if (count < 0) {
console.log("Please enter a number > 0");
return;
}
for (let i = 0; i <= count; i++) {
if (i % 2 != 0) {
console.log(i);
}
}
}
printOdds(100);
printOdds(-100);
// Exercise 2 Section
console.log("EXERCISE 2:\n==========\n");
function checkAge(userName, age) {
if (!userName || !age) {
console.log("Please provide your name and age");
return;
}
let aboveSixteen = `Congrats ${userName}, you can drive!`;
let belowSixteen = `Sorry ${userName}, but you can't drive. Please check back when you're 16.`;
if (age < 16) {
console.log(belowSixteen);
} else {
console.log(aboveSixteen);
}
}
checkAge();
checkAge(15);
checkAge("Brett Bellomy", 30);
checkAge("Naruto Uzumaki", 15);
// Exercise 3 Section
console.log("EXERCISE 4:\n==========\n");
function whichQudrant(xAxisPoint, yAxisPoint) {
if (xAxisPoint == 0) {
console.log(`The coordinate ${xAxisPoint},${yAxisPoint} is on the y Axis!`);
}
else if (yAxisPoint == 0) {
console.log(`The coordinate ${xAxisPoint},${yAxisPoint} is on the x Axis!`);
}
else if (xAxisPoint > 0 && yAxisPoint > 0) {
console.log(`The coordinate ${xAxisPoint},${yAxisPoint} is in Quadrant 1!`);
}
else if (xAxisPoint < 0 && yAxisPoint > 0) {
console.log(`The coordinate ${xAxisPoint},${yAxisPoint} is in Quadrant 2!`);
}
else if (xAxisPoint < 0 && yAxisPoint < 0) {
console.log(`The coordinate ${xAxisPoint},${yAxisPoint} is in Quadrant 3!`);
}
else if (xAxisPoint > 0 && yAxisPoint < 0) {
console.log(`The coordinate ${xAxisPoint},${yAxisPoint} is in Quadrant 4!`);
}
}
whichQudrant(0, 2);
whichQudrant(1, 2);
whichQudrant(-6, 18);
// Exercise 4 Section
console.log("EXERCISE 4:\n==========\n");
function whatTypeOfTriangle(sideOne, sideTwo, sideThree) {
if (sideOne + sideTwo <= sideThree || sideOne + sideThree <= sideTwo || sideTwo + sideThree <= sideOne) {
console.log(`Sorry, this triangle is invalid`);
}
else if (sideOne == sideTwo && sideOne != sideThree) {
console.log(`This is an isosceles triangle`);
}
else if (sideOne == sideThree && sideOne != sideTwo) {
console.log(`This is an isosceles triangle`);
}
else if (sideTwo == sideThree && sideTwo != sideOne) {
console.log(`This is an isosceles triangle`);
}
else if (sideOne == sideTwo && sideTwo == sideThree) {
console.log(`This is an equilateral triangle`);
}
else if (sideOne != sideTwo && sideOne != sideThree) {
console.log('This is a scalene triangle');
}
}
whatTypeOfTriangle(1, 2, 2);
whatTypeOfTriangle(1, 1, 2);