When I printout the javaScript class array, containing several instances from my javascript file, it only shows up on my console, but not on the webpage.  How do I get it to show up on the webpage.  It has to be done from a separte js file not listed on the same page as the html.    This is the code I am using to write out the values in the array.  class Item {     constructor(name, description, date) {       this.name = name;       this.description = description;       this.date = date;     }   }     const items = [];     // Create 7 instances of the Item class   items.push(new Item("item1", "description1", "2022-01-01"));   items.push(new Item("item2", "description2", "2022-01-02"));   items.push(new Item("item3", "description3", "2022-01-03"));   items.push(new Item("item4", "description4", "2022-01-04"));   items.push(new Item("item5", "description5", "2022-01-05"));   items.push(new Item("item6", "description6", "2022-01-06"));   items.push(new Item("item7", "description7", "2022-01-07"));     // Print out the items in the array   for (let i = 0; i < items.length; i++) {     console.log(`Name: ${items[i].name}`);     console.log(`Description: ${items[i].description}`);     console.log(`Date: ${items[i].date}`);     console.log("-------------------");   }

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter11: Advanced Inheritance Concepts
Section: Chapter Questions
Problem 10PE
icon
Related questions
Question
100%

When I printout the javaScript class array, containing several instances from my javascript file, it only shows up on my console, but not on the webpage.  How do I get it to show up on the webpage.  It has to be done from a separte js file not listed on the same page as the html. 

 

This is the code I am using to write out the values in the array. 

class Item {

    constructor(name, description, date) {

      this.name = name;

      this.description = description;

      this.date = date;

    }

  }

 

  const items = [];

 

  // Create 7 instances of the Item class

  items.push(new Item("item1", "description1", "2022-01-01"));

  items.push(new Item("item2", "description2", "2022-01-02"));

  items.push(new Item("item3", "description3", "2022-01-03"));

  items.push(new Item("item4", "description4", "2022-01-04"));

  items.push(new Item("item5", "description5", "2022-01-05"));

  items.push(new Item("item6", "description6", "2022-01-06"));

  items.push(new Item("item7", "description7", "2022-01-07"));

 

  // Print out the items in the array

  for (let i = 0; i < items.length; i++) {

    console.log(`Name: ${items[i].name}`);

    console.log(`Description: ${items[i].description}`);

    console.log(`Date: ${items[i].date}`);

    console.log("-------------------");

  }

Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT