-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
73 lines (59 loc) · 1.56 KB
/
index.js
File metadata and controls
73 lines (59 loc) · 1.56 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
//Task 1
function convertFahrToCelcius(fahr){
let output;
if(Array.isArray(fahr)){
output =(`${JSON.stringify(fahr)} is not a valid number but a/an ${Array.isArray(fahr)?"array":typeof(fahr)}`);
}
else if (isNaN(fahr) || typeof (fahr) === "boolean"){
output = (`${JSON.stringify(fahr)} is not a valid number but a/an ${typeof(fahr)}`);
}
else {
let x = parseFloat(fahr)
let cel = ((x-32) * (5/9))
output = (cel.toFixed(4))
}
console.log(output);
}
convertFahrToCelcius(true);
convertFahrToCelcius("0");
convertFahrToCelcius(0);
convertFahrToCelcius("maryam");
convertFahrToCelcius([]);
convertFahrToCelcius([1,2,3,4]);
convertFahrToCelcius({});
convertFahrToCelcius({d:0});
convertFahrToCelcius("");
//TASK 2
function checkYuGiOh(n){
if (isNaN(n)){
console.log(`invalid parameter: ${n}`)
}
let size = parseInt(n) //convert n to interger
let array = []
for(let i = 0; i < size; i++){
array[i] = i + 1;
array = array.map(i =>{
if (i % 30 === 0){
return 'yu-gi-oh'
}else if (i % 15 === 0){
return 'gi-oh'
}else if (i % 10 === 0){
return 'yu-oh'
}else if (i % 6 === 0){
return 'yu-gi'
}else if (i % 5 === 0){
return 'oh'
}else if (i % 3 === 0){
return 'gi'
}else if (i % 2 === 0){
return 'yu'
}else {return i
}
})
}
console.log(size)
console.log(array)
}checkYuGiOh(10)
checkYuGiOh("5")
checkYuGiOh("fizzbuzz is meh")
checkYuGiOh(100)