i was trying to solve the following using multidimensional array but its not working.
This is the problem
i tried everything , so please could you tell me what is the error in my code.
i don’t know how to create this iframe in codepen. so i am pasting the code here.
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'];
for (let i = 0; i < products.length; i++) { // number 2
// number 3
products[i] = products[i].split(:); //splitting and storing sub array in products[i]
products[i][1] = Number(products[i][1]); //making prices string to number and replacing it with itself
// number 4
total+=products[i][1]; // calculating total of all prices
// number 5
let itemText = products[i][0]+’–$’+products[i][1]; //storing the name + --$ price
const listItem = document.createElement(‘li’);
listItem.textContent = itemText;
list.appendChild(listItem);
}
totalBox.textContent = ‘Total: $’ + total.toFixed(2);
This is the complete iframe code including the predefined code too.
Thank You