How to print this code to the website not to de console?

Hello, how can I print this array straight to the page and not to the console.log?

var fruits = ["mango", "banana", "apple", "cherry"];

for (var i = 0; i < fruits.length; i++) {
  console.log(fruits[i]);
}

have you already searched about dom manipulation? changing the content of the page with javascript?
try reading a bit about that

Yeah, if you keep along with the FCC lessons, you’ll learn this. Don’t worry about it for now.

yes wasn’t that hard easy to do it like this
html

<p id="arrayText"></p>

js

var fruits = ["mango", "banana", "apple", "cherry"];

for (var i = 0; i < fruits.length; i++) {
  document.getElementById("arrayText").innerHTML = fruits.toString();
}

thanks guys

But now I been trying to do it with images but for some reason is not working
html

<div id="arrayImages"></div>

js

var images = ["1.png", "2.png", "3.png"];

for (var i = 0; i < images.length; i++) {
  document.getElementById("arrayImages").src = images.src;
}

you are not creating any img element

check out createElement()

1 Like