File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed
full-stack-dev/3-js-basic/4-basics/4-11-training-module Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments