-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathassignment.js
More file actions
78 lines (57 loc) · 1.62 KB
/
assignment.js
File metadata and controls
78 lines (57 loc) · 1.62 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
// kilometerToMeter
function kilometerToMeter(km){
var meter
if(km >=0){
meter = km*1000;
}else if(km <0){
console.log("Distnce cannot be negative"); // Error massage here;
}
return meter;
}
// budgetCalculator
function budgetCalculator(watch,phone,laptop){
var total;
if(watch>=0 && phone>=0 && laptop>=0){
var amountOfWatch = watch*50;
var amountOfPhone = phone*100;
var amountOfLaptop = laptop*500;
total = amountOfWatch + amountOfPhone + amountOfLaptop;
}else{
console.log("Product cannot be negative value"); // Error massage here;
}
return total;
}
// hotelCost
function hotelCost(day){
var cost;
if(day <= 10 && day >= 0){
var cost = day*100;
}else if(day <= 20 && day >= 0){
var firstPart = 10*100;
var remaining = day-10;
var secondPart = remaining*80;
var cost = firstPart + secondPart;
}else if(day >20 && day >= 0){
var firstPart = 10*100;
var secondPart = 10*80;
var remaining = day-20;
var thirdPart = remaining*50;
var cost = firstPart + secondPart + thirdPart
}else{
console.log("Day cannot be negative"); // Error massage here;
}
return cost;
}
// megaFriend
function megaFriend(arr){
var result = "";
for(var i = 0;i<arr.length;i++){
var currentName = arr[i];
if(currentName.length>result.length){
result = arr[i];
}else if(currentName.length < 0){
console.log("Error"); // Error massage here;
}
}
return result;
}