Greetings, I am glad to be here.
I am just now at the Arrays learning, trying the ’ [Active learning: Printing those products!’ assignment.
I regularly use the Show Solution option, but I would really appreciate feedback on my code, which I’m pretty sure wouldn’t even work properly (regardless of the live output, which sometimes tends to break for me, even when I do enter correct solutions code).
const list = document.querySelector(’.output ul’);
const totalBox = document.querySelector(’.output p’);
let total = 0;
list.innerHTML = ‘’;
totalBox.textContent = ‘’;
// number 1
let products = [‘Underpants:6.99’,
‘Socks:5.99’,
‘T-shirt:14.99’,
‘Trousers:31.99’,
‘Shoes:23.99’];
// number 2
for (let i = 0; i < products.length; i++) {
// number 3
let prices = products[i].split(’:’);
let stringPrices = Number(prices);for (let z = 0; z < stringPrices.length; z++) {
// number 4
let total[z] += stringPrices
}// number 5
let itemText =${products[i] — ${prices[i]}
;const listItem = document.createElement(‘li’);
listItem.textContent = itemText;
list.appendChild(listItem);
}totalBox.textContent = ‘Total: $’ + total.toFixed(2);
Thanks in advance to all helpers!