Skip to content

Commit c8d3876

Browse files
adding exam prep 07
1 parent ce5bf84 commit c8d3876

File tree

6 files changed

+220
-0
lines changed

6 files changed

+220
-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: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
function main(input) {
2+
let price = Number(input[0]);
3+
let kgOfLuggage = Number(input[1]);
4+
let dayBeforeDeparture = Number(input[2]);
5+
let numOfLuggage = Number(input[3]);
6+
let totalLuggagePrice = 0;
7+
8+
if (kgOfLuggage < 10) {
9+
totalLuggagePrice = price * 0.2;
10+
} else if (kgOfLuggage >= 10 && kgOfLuggage <= 20) {
11+
totalLuggagePrice = price * 0.5;
12+
} else {
13+
totalLuggagePrice = price;
14+
}
15+
16+
if (dayBeforeDeparture < 7) {
17+
totalLuggagePrice += totalLuggagePrice * 0.4;
18+
} else if (dayBeforeDeparture >= 7 && dayBeforeDeparture <= 30) {
19+
totalLuggagePrice += totalLuggagePrice * 0.15;
20+
} else {
21+
totalLuggagePrice += totalLuggagePrice * 0.1;
22+
}
23+
24+
totalLuggagePrice *= numOfLuggage;
25+
26+
console.log(`The total price of bags is: ${totalLuggagePrice.toFixed(2)} lv.`);
27+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
function main(input) {
2+
let orders = Number(input[0]);
3+
let typeOfUnit = input[1];
4+
let delivery = input[2];
5+
let price, totalPrice = 0;
6+
7+
if (orders < 10) {
8+
console.log("Invalid order");
9+
} else {
10+
switch (typeOfUnit) {
11+
case "90X130" :
12+
price = orders * 110;
13+
if (orders > 60) {
14+
totalPrice = price - (price * 0.08);
15+
} else if (orders > 30) {
16+
totalPrice = price - (price * 0.05);
17+
} else {
18+
totalPrice = price;
19+
}
20+
break;
21+
case "100X150" :
22+
price = orders * 140;
23+
if (orders > 80) {
24+
totalPrice = price - (price * 0.1);
25+
} else if (orders > 40) {
26+
totalPrice = price - (price * 0.06);
27+
} else {
28+
totalPrice = price;
29+
}
30+
break;
31+
case "130X180" :
32+
price = orders * 190;
33+
if (orders > 50) {
34+
totalPrice = price - (price * 0.12);
35+
} else if (orders > 20) {
36+
totalPrice = price - (price * 0.07);
37+
} else {
38+
totalPrice = price;
39+
}
40+
break;
41+
case "200X300" :
42+
price = orders * 250;
43+
if (orders > 50) {
44+
totalPrice = price - (price * 0.14);
45+
} else if (orders > 25) {
46+
totalPrice = price - (price * 0.09);
47+
} else {
48+
totalPrice = price;
49+
}
50+
break;
51+
}
52+
53+
if (delivery === "With delivery") {
54+
totalPrice += 60;
55+
}
56+
if (orders > 99) {
57+
totalPrice = totalPrice - (totalPrice * 0.04);
58+
}
59+
console.log(`${totalPrice.toFixed(2)} BGN`);
60+
}
61+
}

exams/more-exams/exam07/04-balls.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
function main(input) {
2+
let totalPoints = 0;
3+
let redCount = 0;
4+
let orangeCount = 0;
5+
let yellowCount = 0;
6+
let whiteCount = 0;
7+
let otherColorsCount = 0;
8+
let blackDivisionsCount = 0;
9+
10+
let N = Number(input[0]);
11+
12+
for (let i = 1; i <= N; i++) {
13+
let color = input[i];
14+
15+
switch (color) {
16+
case "red":
17+
totalPoints += 5;
18+
redCount++;
19+
break;
20+
case "orange":
21+
totalPoints += 10;
22+
orangeCount++;
23+
break;
24+
case "yellow":
25+
totalPoints += 15;
26+
yellowCount++;
27+
break;
28+
case "white":
29+
totalPoints += 20;
30+
whiteCount++;
31+
break;
32+
case "black":
33+
totalPoints = Math.floor(totalPoints / 2);
34+
blackDivisionsCount++;
35+
break;
36+
default:
37+
otherColorsCount++;
38+
}
39+
}
40+
41+
console.log(`Total points: ${totalPoints}`);
42+
console.log(`Red balls: ${redCount}`);
43+
console.log(`Orange balls: ${orangeCount}`);
44+
console.log(`Yellow balls: ${yellowCount}`);
45+
console.log(`White balls: ${whiteCount}`);
46+
console.log(`Other colors picked: ${otherColorsCount}`);
47+
console.log(`Divides from black balls: ${blackDivisionsCount}`);
48+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
function main(input) {
2+
let bestPlayer = "";
3+
let bestGoals = 0;
4+
let hatTrick = false;
5+
6+
let i = 0;
7+
while (true) {
8+
let playerName = input[i];
9+
if (playerName === "END") {
10+
break;
11+
}
12+
13+
let goals = Number(input[i + 1]);
14+
15+
if (goals >= 10) {
16+
bestPlayer = playerName;
17+
bestGoals = goals;
18+
hatTrick = true;
19+
break;
20+
}
21+
22+
if (goals > bestGoals) {
23+
bestPlayer = playerName;
24+
bestGoals = goals;
25+
if (goals >= 3) {
26+
hatTrick = true;
27+
} else {
28+
hatTrick = false;
29+
}
30+
}
31+
i += 2;
32+
}
33+
34+
console.log(bestPlayer + " is the best player!");
35+
if (hatTrick) {
36+
console.log("He has scored " + bestGoals + " goals and made a hat-trick !!!");
37+
} else {
38+
console.log("He has scored " + bestGoals + " goals.");
39+
}
40+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
function main(input) {
2+
let start = Number(input[0]);
3+
let end = Number(input[1]);
4+
5+
let startUnits = start % 10;
6+
let startTens = Math.floor(start / 10) % 10;
7+
let startHundreds = Math.floor(start / 100) % 10;
8+
let startThousands = Math.floor(start / 1000) % 10;
9+
10+
let endUnits = end % 10;
11+
let endTens = Math.floor(end / 10) % 10;
12+
let endHundreds = Math.floor(end / 100) % 10;
13+
let endThousands = Math.floor(end / 1000) % 10;
14+
15+
let result = '';
16+
17+
for (let i = startThousands; i <= endThousands; i++) {
18+
for (let j = startHundreds; j <= endHundreds; j++) {
19+
for (let k = startTens; k <= endTens; k++) {
20+
for (let l = startUnits; l <= endUnits; l++) {
21+
if (i % 2 !== 0 && j % 2 !== 0 && k % 2 !== 0 && l % 2 !== 0) {
22+
result += `${i}${j}${k}${l} `;
23+
}
24+
}
25+
}
26+
}
27+
}
28+
29+
console.log(result.trim());
30+
}

0 commit comments

Comments
 (0)