Files
JS/06_js-debug/faq/extraction-bsp.html
Philippe Torrel c6d9611e81
2026-08-18 14:27:34 +02:00

34 lines
860 B
HTML

<!doctype html>
<html lang="de">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Extraction sum</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.8/dist/css/bootstrap.min.css" rel="stylesheet" />
</head>
<body>
<main>
<div class="container py-5">
<h1>Extraction sum</h1>
</div>
</main>
<script>
'use strict';
const products = [
{ name: 'Product1', price: 10.5 },
{ name: 'Product1', price: 10.5 },
];
// Extraction
const sum = (a, b) => {
return Number(a) + Number(b);
};
const totals = products.map((product) => Number(product.price));
const totalPrice = totals.reduce(sum, 0);
console.log(`total: ${totalPrice}`);
</script>
</body>
</html>