- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathassignment.js
More file actions
Latest commit
81 lines (68 loc) · 2.24 KB
/
Copy pathassignment.js
File metadata and controls
81 lines (68 loc) · 2.24 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
// https://github.com/prosany/PH-JavaScript_FirstAssignment
// First Project
functionkilometerToMeter(kilometer){
// if the kilometer value is less than or equal to 0 then return this error.
if(kilometer<=0){
return'Error! The value of kilometer is less than 1';
}
else{
varmeter=kilometer*1000;
returnmeter;
}
}
varconvertValue=kilometerToMeter(1);
// Second Project
functionbudgetCalculator(watch,phone,laptop){
if(watch<=0||phone<=0||laptop<=0){
return'Error! field cannot be empty or less then 1.';
}
else{
varwatchPrice=watch*50;
varphonePrice=phone*100;
varlaptopPrice=laptop*500;
totalPrice=watchPrice+phonePrice+laptopPrice;
}
returntotalPrice;
}
vartotalCost=budgetCalculator(4,5,2);
// Third Project
functionhotelCost(totalStay){
varhotelCheckoutCost=0;
if(totalStay<=0){
return'Please book your room first to calculate amount.';
}
elseif(totalStay<=10){
hotelCheckoutCost=totalStay*100;
}
elseif(totalStay<=20){
varfirstTenDays=10*100;
varremaningDays=totalStay-10;
varsecondTenDays=remaningDays*80;
hotelCheckoutCost=firstTenDays+secondTenDays;
}
else{
varfirstTenDays=10*100;
varsecondTenDays=10*80;
varremaningDays=totalStay-20;
varthirdTenOrMoreDays=remaningDays*50;
hotelCheckoutCost=firstTenDays+secondTenDays+thirdTenOrMoreDays;
}
returnhotelCheckoutCost;
}
varhotelTotalCost=hotelCost(30);
// Fourth Project
functionmegaFriend(arr){
varfriendLargeName=arr[0];
for(vari=0;i<arr.length;i++){
varelement=arr[i];
if(element.length<=0){
return'Error! Name field cannot be empty.';
}
elseif(friendLargeName.length<element.length){
friendLargeName=element;
}
}
returnfriendLargeName;
}
varmegaFriendList=['Meher','Muniya','Mahabub','Ashik','Shakil','Tanvir'];
varlongestName=megaFriend(megaFriendList);