-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask-06.js
More file actions
33 lines (28 loc) · 1.36 KB
/
Copy pathtask-06.js
File metadata and controls
33 lines (28 loc) · 1.36 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
"use strict";
// Напиши функцию calculateTotalPrice(allProdcuts, productName),
// которая получает массив объектов и имя продукта (значение свойства name).
// Возвращает общую стоимость продукта (цена * количество).
// Вызовы функции для проверки работоспособности твоей реализации.
const products = [
{ name: "Радар", price: 1300, quantity: 4 },
{ name: "Сканер", price: 2700, quantity: 3 },
{ name: "Дроид", price: 400, quantity: 7 },
{ name: "Захват", price: 1200, quantity: 2 }
];
const calculateTotalPrice = function(allProdcuts, productName) {
let total;
for (const product of allProdcuts) {
// console.log(product.price);
if (product.name.includes(productName)) {
total = product.quantity * product.price;
}
}
return `${productName} --- ${total}`;
};
/*
* Вызовы функции для проверки работоспособности твоей реализации.
*/
console.log(calculateTotalPrice(products, "Радар")); // 5200
console.log(calculateTotalPrice(products, "Дроид")); // 2800
console.log(calculateTotalPrice(products, "Сканер")); // 8100
console.log(calculateTotalPrice(products, "Захват")); // 2400