-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathassignment.js
More file actions
66 lines (54 loc) · 1.5 KB
/
assignment.js
File metadata and controls
66 lines (54 loc) · 1.5 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
// ...............github.link..............
// https://github.com/faysal253/assignment3
// 01
// kilometerToMeter
function kilometerToMeter(kilometer) {
if (kilometer >= 0) {
var meter = kilometer * 1000;
return meter;
} else {
return 'Kilometer value is not be negative';
}
}
// 02
// budgetCalculator
function budgetCalculator(watch, mobile, laptop){
var watchPrice = watch * 50;
var mobilePrice = mobile * 100;
var laptopPrice = laptop * 500;
// calculate total budget
var totalPrice = (watchPrice + mobilePrice + laptopPrice);
return totalPrice;
}
// 04
// megaFriends
function megaFriends(friendsName){
var longestName = "";
for(i = 0; i < friendsName.length; i++){
if(friendsName[i].length > longestName.length){
longestName = friendsName[i];
}
}return longestName;
}
// 03
// hotelCost
function hotelCost(dayCount) {
var totalPrice = 0;
if (dayCount <= 10) {
totalPrice = dayCount * 100;
} else if (dayCount <= 20) {
var firstStayPrice = 10 * 100;
var secondStay = dayCount - 10;
var secondStayPrice = secondStay * 80;
// TOTAL
var totalPrice = firstStayPrice + secondStayPrice;
} else {
var firstStayPrice = 10 * 100;
var secondStayPrice = 10 * 80;
var thirdStay = dayCount - 20;
var thirdStayPrice = thirdStay * 50;
// TOTAL
var totalPrice = firstStayPrice + secondStayPrice + thirdStayPrice;
}
return totalPrice;
}