Array concepts Active learning: Printing those products Issue #26329
Labels
Content:Learn:JavaScript
Learning area JavaScript docs
needs info
Needs more information to review or act on.
MDN URL
https://developer.mozilla.org/en-US/docs/Learn/JavaScript/First_steps/Arrays
What specific section or headline is this issue about?
Active learning: Printing those products
What information was incorrect, unhelpful, or incomplete?
const list = document.querySelector('.output ul'); // this area create issue for us
const totalBox = document.querySelector('.output p');
let total = 0;
list.innerHTML = ''; // caught TypeError: Cannot set properties of null (setting 'innerHTML').
totalBox.textContent = '';
const products = [
'Underpants:6.99',
'Socks:5.99',
'T-shirt:14.99',
'Trousers:31.99',
'Shoes:23.99',
];
for (const product of products) {
const subArray = product.split(':');
const name = subArray[0];
const price = Number(subArray[1]);
total += price;
const itemText =
${name} — $${price}
;const listItem = document.createElement('li');
listItem.textContent = itemText;
list.appendChild(listItem);
}
totalBox.textContent =
Total: $${total.toFixed(2)}
;What did you expect to see?
Do you have any supporting links, references, or citations?
No response
Do you have anything more you want to share?
No response
MDN metadata
Page report details
en-us/learn/javascript/first_steps/arrays
The text was updated successfully, but these errors were encountered: