Skip to content

Commit 984fec2

Browse files
adding exam preparation
1 parent fb7a035 commit 984fec2

File tree

6 files changed

+147
-0
lines changed

6 files changed

+147
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
function agencyProfit(input) {
2+
let airlineName = input[0];
3+
let adultTickets = Number(input[1]);
4+
let childTickets = Number(input[2]);
5+
let adultTicketPrice = Number(input[3]);
6+
let serviceFee = Number(input[4]);
7+
8+
let childTicketPrice = adultTicketPrice * 0.3;
9+
let totalAdultPrice = adultTickets * (adultTicketPrice + serviceFee);
10+
let totalChildPrice = childTickets * (childTicketPrice + serviceFee);
11+
let totalProfit = (totalAdultPrice + totalChildPrice) * 0.2;
12+
13+
console.log(`The profit of your agency from ${airlineName} tickets is ${totalProfit.toFixed(2)} lv.`);
14+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
function catWalk(input) {
2+
let minutesPerWalk = Number(input[0]);
3+
let walksPerDay = Number(input[1]);
4+
let caloriesIntakePerDay = Number(input[2]);
5+
6+
let totalMinutesPerDay = minutesPerWalk * walksPerDay;
7+
let burnedCaloriesPerDay = totalMinutesPerDay * 5;
8+
9+
if (burnedCaloriesPerDay >= caloriesIntakePerDay * 0.5) {
10+
return `Yes, the walk for your cat is enough. Burned calories per day: ${burnedCaloriesPerDay}.`;
11+
} else {
12+
return `No, the walk for your cat is not enough. Burned calories per day: ${burnedCaloriesPerDay}.`;
13+
}
14+
}

exams/exam-preparation/03-club.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
function calculateDrinkCost(input) {
2+
let drink = input[0];
3+
let sugar = input[1];
4+
let quantity = Number(input[2]);
5+
6+
let price = 0;
7+
switch (drink) {
8+
case 'Espresso':
9+
price = (sugar === 'Without') ? 0.90 * 0.65 : (sugar === 'Normal') ? 1.00 : 1.20;
10+
if (quantity >= 5) price *= 0.75;
11+
break;
12+
case 'Cappuccino':
13+
price = (sugar === 'Without') ? 1.00 * 0.65 : (sugar === 'Normal') ? 1.20 : 1.60;
14+
break;
15+
case 'Tea':
16+
price = (sugar === 'Without') ? 0.50 * 0.65 : (sugar === 'Normal') ? 0.60 : 0.70;
17+
break;
18+
}
19+
20+
let totalCost = price * quantity;
21+
22+
if (totalCost > 15) {
23+
totalCost *= 0.80;
24+
}
25+
26+
return `You bought ${quantity} cups of ${drink} for ${totalCost.toFixed(2)} lv.`;
27+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
function trekkingMania(input) {
2+
let groups = Number(input[0]);
3+
let musala = 0, monblan = 0, kilimanjaro = 0, k2 = 0, everest = 0;
4+
let totalPeople = 0;
5+
6+
for(let i = 1; i <= groups; i++) {
7+
let peopleInGroup = Number(input[i]);
8+
totalPeople += peopleInGroup;
9+
10+
if (peopleInGroup <= 5){
11+
musala += peopleInGroup;
12+
} else if (peopleInGroup > 5 && peopleInGroup <= 12) {
13+
monblan += peopleInGroup;
14+
} else if (peopleInGroup > 12 && peopleInGroup <= 25) {
15+
kilimanjaro += peopleInGroup;
16+
} else if (peopleInGroup > 25 && peopleInGroup <= 40) {
17+
k2 += peopleInGroup;
18+
} else {
19+
everest += peopleInGroup;
20+
}
21+
}
22+
23+
let result = [
24+
(musala / totalPeople) * 100,
25+
(monblan / totalPeople) * 100,
26+
(kilimanjaro / totalPeople) * 100,
27+
(k2 / totalPeople) * 100,
28+
(everest / totalPeople) * 100
29+
].map(x => `${x.toFixed(2)}%`).join('\n');
30+
31+
return result;
32+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
function movieStars(input) {
2+
let budget = Number(input[0]);
3+
let remainingBudget = budget;
4+
let i = 1;
5+
6+
while (input[i] != "ACTION") {
7+
let actorName = input[i];
8+
let payment;
9+
if (actorName.length <= 15) {
10+
payment = Number(input[++i]);
11+
} else {
12+
payment = remainingBudget * 0.2;
13+
}
14+
15+
remainingBudget -= payment;
16+
17+
if (remainingBudget < 0) {
18+
let neededBudget = Math.abs(remainingBudget);
19+
return `We need ${neededBudget.toFixed(2)} leva for our actors.`;
20+
}
21+
22+
i++;
23+
}
24+
25+
return `We are left with ${remainingBudget.toFixed(2)} leva.`;
26+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
function basketballTournaments(input) {
2+
let totalMatches = 0;
3+
let wins = 0;
4+
let losses = 0;
5+
let i = 0;
6+
7+
while (input[i] !== "End of tournaments") {
8+
let tournamentName = input[i++];
9+
let matches = Number(input[i++]);
10+
11+
for (let j = 0; j < matches; j++) {
12+
let desiPoints = Number(input[i++]);
13+
let opponentPoints = Number(input[i++]);
14+
15+
let difference = Math.abs(desiPoints - opponentPoints);
16+
17+
if (desiPoints > opponentPoints) {
18+
console.log(`Game ${j + 1} of tournament ${tournamentName}: win with ${difference} points.`);
19+
wins++;
20+
} else {
21+
console.log(`Game ${j + 1} of tournament ${tournamentName}: lost with ${difference} points.`);
22+
losses++;
23+
}
24+
25+
totalMatches++;
26+
}
27+
}
28+
29+
let winPercentage = (wins / totalMatches) * 100;
30+
let lossPercentage = (losses / totalMatches) * 100;
31+
32+
console.log(`${winPercentage.toFixed(2)}% matches win`);
33+
console.log(`${lossPercentage.toFixed(2)}% matches lost`);
34+
}

0 commit comments

Comments
 (0)