-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathassignment.js
More file actions
92 lines (82 loc) · 2.44 KB
/
assignment.js
File metadata and controls
92 lines (82 loc) · 2.44 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
82
83
84
85
86
87
88
89
90
91
92
//problem 1 anaToVori
function anaToVori(ana) {
if (typeof ana != "number") {
return "Enter a valid number";
}
if (ana < 0) {
return "Enter a positive number";
}
let vori = ana / 16;
return vori;
}
// console.log(anaToVori(32));
//problem 2 pandaCost
function pandaCost(singarQuantity, somosaQuantity, jilapiQuantity) {
if (
(typeof singarQuantity,
typeof somosaQuantity,
typeof jilapiQuantity != "number")
) {
return "Enter a valid number";
}
if (singarQuantity < 0 || somosaQuantity < 0 || jilapiQuantity < 0) {
return "Enter a positive number";
}
// pricing table
let perSingaraPrice = 7 * singarQuantity;
let perSomosaPrice = 10 * somosaQuantity;
let perJilapiPrice = 15 * jilapiQuantity;
const totalPrice = perSingaraPrice + perSomosaPrice + perJilapiPrice;
return totalPrice;
}
// console.log(pandaCost(1, 2, 3));
//problem 3 picnicBudget
function picnicBudget(person) {
if (typeof person != "number") {
return "you can only input a number";
}
let theFirst100PerPerson = 5000;
let theSecond100PerPerson = 4000;
let moreThan200perPerson = 3000;
let restPerson = 0;
let totalPrice = 0;
if (person <= 100) {
//first 100 people
theFirst100PerPerson *= person;
return theFirst100PerPerson;
} else if (person <= 200) {
// the second 100 people
theFirst100PerPerson *= 100;
restPerson = person - 100;
theSecond100PerPerson *= restPerson;
totalPrice = theFirst100PerPerson + theSecond100PerPerson;
return totalPrice;
} else {
//more than 200
theFirst100PerPerson *= 100;
theSecond100PerPerson *= 100;
restPerson = person - 200;
moreThan200perPerson *= restPerson;
totalPrice =
theFirst100PerPerson + theSecond100PerPerson + moreThan200perPerson;
return totalPrice;
}
}
// console.log(picnicBudget(98));
//problem 4 oddFriends
function oddFriend(friendsList) {
if (Array.isArray(friendsList)) {
let oddFriend = "";
for (const element of friendsList) {
if (element.length % 2 != 0) {
oddFriend = element;
break;
}
}
return oddFriend;
} else {
return "Enter a Array";
}
}
const myBestFried = ["Shofikul", "Opo", "Raihan", "Amdadul", "Dilu", "Rifat","ALam"];
// console.log(oddFriend(myBestFried));