-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patha.js
More file actions
79 lines (63 loc) · 2.87 KB
/
Copy patha.js
File metadata and controls
79 lines (63 loc) · 2.87 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
// problem no. 1
function seerToMon(seer) {
if ((typeof seer === 'number') && (seer % 1 === 0) && (seer >= 0)) { // checked whether input 'seer' type is integer number or not and greater than or equal to 0;
let mon = seer / 40;
return mon;
}
else { // execute if input is 'string',less than 0, double etc.
return console.log('Error! Please give an integer number.');
}
}
console.log(seerToMon(90));
// problem no. 2
function totalSales(shirts, pants, shoes) {
if ((typeof shirts && typeof pants && typeof shoes === 'number') && ((shirts && pants && shoes) % 1 === 0) && (shirts && pants && shoes) >= 0) { // checked whether input 'shirts, pants,shoes' type is integer number or not and greater than or equal to 0;
return (shirts * 100) + (pants * 200) + (shoes * 500);
}
else { // execute if input is 'string',less than 0, double etc.
return console.log('Error! Please give an integer number.');
}
}
console.log(totalSales(0, 5, 0));
// problem no. 3
function deliveryCost(numberOfTshirts) {
if (typeof numberOfTshirts === 'number' && (numberOfTshirts % 1 === 0) && numberOfTshirts >= 0) { // checked whether input 'numberOfTshirts' type is number or not and greater than or equal to 0;
if (numberOfTshirts <= 100) { // execute for less equal to 100 t-shirts. t-shirts.
const totalDeliveryCost = numberOfTshirts * 100;
return totalDeliveryCost;
}
else if (numberOfTshirts <= 200) { // execute for less equal to 200 t-shirts.
let totalDeliveryCost = 100 * 100;
const restTshirts = numberOfTshirts - 100;
totalDeliveryCost = totalDeliveryCost + (restTshirts * 80);
return totalDeliveryCost;
}
else { // execute for greater than 200 t-shirts.
let totalDeliveryCost = (100 * 100) + (100 * 80);
const restTshirts = numberOfTshirts - 200;
totalDeliveryCost = totalDeliveryCost + (restTshirts * 50);
return totalDeliveryCost;
}
}
else { // execute if input is 'string',less than 0, double etc.
return console.log('Error! Please give an integer number.');
}
}
console.log(deliveryCost(101))
// problem no. 4
let arr = ['nur', 'turu', 'nilu', 'rahim', 'karim']
function perfectFriend(friendsArr) {
if (Array.isArray(friendsArr)) { // cheaked input is an array or not.
let friendName = friendsArr[0]
for (const friend of friendsArr) {
if (friendName.length < friend.length) { // compared the length among the strings of the input array.
friendName = friend;
}
}
return friendName; // returned the final result.
}
else { // execute if input is not an array
console.log('Please Enter an array that contain strings');
}
}
console.log(perfectFriend(arr));