-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
110 lines (90 loc) · 3.13 KB
/
main.js
File metadata and controls
110 lines (90 loc) · 3.13 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
//------------------- Assignment 1 -------------------
function sayHello(theName, theGender) {
// Your Code Here
console.log(
`Hello ${
theGender === "Male" ? "Mr " : theGender === "Female" ? "Miss " : ""
}${theName}`
);
}
// Needed Output
sayHello("Osama", "Male"); // "Hello Mr Osama"
sayHello("Eman", "Female"); // "Hello Miss Eman"
sayHello("Sameh"); // "Hello Sameh"
console.log("");
//------------------- Assignment 2 -------------------
function calculate(firstNum, secondNum, operation) {
// Your Code Here
if (secondNum === undefined) console.log("Second Number Not Found");
else if (operation === undefined || operation === "add")
console.log(firstNum + secondNum);
else if (operation === "subtract") console.log(firstNum - secondNum);
else if (operation === "multiply") console.log(firstNum * secondNum);
}
// Needed Output
calculate(20); // Second Number Not Found
calculate(20, 30); // 50
calculate(20, 30, "add"); // 50
calculate(20, 30, "subtract"); // -10
calculate(20, 30, "multiply"); // 600
console.log("");
//------------------- Assignment 3 -------------------
function ageInTime(theAge) {
// Your Code Here
if (theAge > 10 && theAge < 100) {
console.log(`Months => ${12 * theAge} Months`);
console.log(`Days => ${365 * theAge} Days`);
console.log(`Hours => ${365 * theAge * 24} Hours`);
console.log(`Minutes => ${365 * theAge * 24 * 60} Minutes`);
console.log(`Seconds => ${365 * theAge * 24 * 60 * 60} Seconds`);
} else {
console.log("Age Out Of Range");
}
}
// Needed Output
ageInTime(110); // Age Out Of Range
ageInTime(38); // Months Example => 456 Months
console.log("");
//------------------- Assignment 4 -------------------
function checkStatus(a, b, c) {
let arr = [a, b, c];
for (let i = 0; i < arr.length; i++) {
if (typeof arr[i] === "string") a = arr[i];
else if (typeof arr[i] === "number") b = arr[i];
else if (typeof arr[i] === "boolean") c = arr[i];
}
console.log(
`"Hello ${a}, Your Age Is ${b}, You Are ${
c ? "Available" : "Not Available"
} For Hire"`
);
}
// Needed Output
checkStatus("Osama", 38, true); // "Hello Osama, Your Age Is 38, You Are Available For Hire"
checkStatus(38, "Osama", true); // "Hello Osama, Your Age Is 38, You Are Available For Hire"
checkStatus(true, 38, "Osama"); // "Hello Osama, Your Age Is 38, You Are Available For Hire"
checkStatus(false, "Osama", 38); // "Hello Osama, Your Age Is 38, You Are Not Available For Hire"
console.log("");
//------------------- Assignment 5 -------------------
function createSelectBox(startYear, endYear) {
// Your Code Here
document.write("<select>");
for (let i = startYear; i <= endYear; i++) {
document.write(`<option value="${i}">${i}</option>`);
}
document.write("</select>");
}
createSelectBox(2000, 2021);
//------------------- Assignment 6 -------------------
function multiply(...numbers) {
let result = 1;
for (let i = 0; i < numbers.length; i++) {
if (typeof numbers[i] === "number") {
result *= parseInt(numbers[i]);
}
}
console.log(result);
}
multiply(10, 20); // 200
multiply("A", 10, 30); // 300
multiply(100.5, 10, "B"); // 1000