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("-------------------"); }
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("-------------------");
}
![](/static/compass_v2/shared-icons/check-mark.png)
Step by step
Solved in 2 steps
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)