Skip to content

Commit 504ef64

Browse files
committed
[TM-4.11/st-compl] training-module
Solving 1 tasks. Getting "discounted" price. FS-dev: B-3 / JS basic
1 parent 31a22fa commit 504ef64

File tree

1 file changed

+19
-0
lines changed
  • full-stack-dev/3-js-basic/4-basics/4-11-training-module

1 file changed

+19
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
'use strict';
2+
3+
// Задание 1:
4+
// Нужно написать функцию, которая рассчитает итоговую цену всей покупки с учетом скидки.
5+
// 1. Сначала нужно узнать "первичную" цену (общую стоимость без скидки).
6+
// 2. Затем нужно рассчитать, сколько составляет скидка от этой цены.
7+
// 3. Вычесть сумму скидки из "первичной" цены, чтобы получить (итоговую) цену.
8+
9+
function getFinalPrice(price = 0, quantity = 0, discount = 0) {
10+
const initPrice = price * quantity;
11+
const discountSum = initPrice * (discount / 100);
12+
const finalPrice = initPrice - discountSum;
13+
14+
return finalPrice;
15+
}
16+
17+
console.log(getFinalPrice(100, 3, 15)); // 255
18+
console.log(getFinalPrice(50, 2, 10)); // 90
19+
console.log(getFinalPrice()); // 0

0 commit comments

Comments
 (0)