Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Array concepts Active learning: Printing those products Issue #26329

Closed
HimansuWebCoder opened this issue Apr 21, 2023 · 1 comment
Closed

Array concepts Active learning: Printing those products Issue #26329

HimansuWebCoder opened this issue Apr 21, 2023 · 1 comment
Labels
Content:Learn:JavaScript Learning area JavaScript docs needs info Needs more information to review or act on.

Comments

@HimansuWebCoder
Copy link

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?

    <script>
      const list = document.querySelector(".output1");
      const totalBox = document.querySelector(".output2");
      let total = 0;
      list.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)}`;
    

    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
    @HimansuWebCoder HimansuWebCoder added the needs triage Triage needed by staff and/or partners. Automatically applied when an issue is opened. label Apr 21, 2023
    @github-actions github-actions bot added the Content:Learn:JavaScript Learning area JavaScript docs label Apr 21, 2023
    @Josh-Cena
    Copy link
    Member

    Not sure why it doesn't work for you, because it surely does for me:

    image

    You can check the source code here: https://github.com/mdn/content/blob/main/files/en-us/learn/javascript/first_steps/arrays/index.md

    We can reopen if there actually turns out to be an issue

    @Josh-Cena Josh-Cena closed this as not planned Won't fix, can't repro, duplicate, stale May 20, 2023
    @Josh-Cena Josh-Cena added needs info Needs more information to review or act on. and removed needs triage Triage needed by staff and/or partners. Automatically applied when an issue is opened. labels May 20, 2023
    @github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 1, 2024
    Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
    Labels
    Content:Learn:JavaScript Learning area JavaScript docs needs info Needs more information to review or act on.
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants