From aa921cc88df48d676e81cac8d9810a0853f81fc2 Mon Sep 17 00:00:00 2001 From: Yarninator Date: Mon, 5 Aug 2024 13:14:24 +0200 Subject: [PATCH] Added total price --- index.html | 8 ++++++-- scripts/main.js | 14 ++++++++------ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/index.html b/index.html index 8931772..bd18677 100644 --- a/index.html +++ b/index.html @@ -70,9 +70,13 @@ Home - + - +

€ 0

+ + diff --git a/scripts/main.js b/scripts/main.js index 23196b9..7c638e0 100644 --- a/scripts/main.js +++ b/scripts/main.js @@ -6,6 +6,8 @@ const api_url = "http://127.0.0.1:8000" var to_fill_product_index = 0 +var total_price = 0 + async function makeAPIRequest(request) { try { const response = await fetch(request); @@ -38,15 +40,15 @@ async function loadProducts() { const product_placeholders = document.getElementsByClassName('product_placeholder') const chosen_product_placeholder = product_placeholders[to_fill_product_index] - var image_product = chosen_product_placeholder.getElementsByClassName('product_image')[0] - var price_product = chosen_product_placeholder.getElementsByClassName('product_price')[0] - - console.log(chosen_product_placeholder) - console.log(image_product) - console.log(price_product) + const image_product = chosen_product_placeholder.getElementsByClassName('product_image')[0] + const price_product = chosen_product_placeholder.getElementsByClassName('product_price')[0] + const total_price_holder = document.getElementById("totalprice") + + total_price += chosen_product.price image_product.setAttribute('href', api_url + "/icons/" + chosen_product.image_filename); price_product.textContent = "\u20AC " + chosen_product.price + total_price_holder.textContent = "\u20AC " + total_price to_fill_product_index += 1 });