Files
CSWProj/script.js
2025-12-03 12:21:29 +01:00

36 lines
926 B
JavaScript

const products = [
{ name: "Laptop Pro 15", price: 1499 },
{ name: "Kabellose Maus X2", price: 49 },
{ name: "Gaming Tastatur RGB", price: 89 },
{ name: "4K Monitor UltraSharp", price: 399 },
{ name: "USB-C Dockingstation", price: 129 }
];
const list = document.getElementById("productList");
const text = document.getElementById("textFilter");
const price = document.getElementById("priceFilter");
function showProducts() {
const t = text.value.toLowerCase();
const p = Number(price.value);
list.innerHTML = "";
products
.filter(item =>
item.name.toLowerCase().includes(t) &&
(!p || item.price <= p)
)
.forEach(item => {
list.innerHTML += `<div class="product">
<strong>${item.name}</strong><br>
Preis: ${item.price}
</div>`;
});
}
text.addEventListener("input", showProducts);
price.addEventListener("input", showProducts);
showProducts();