Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Why won't my Javascript code alter the HTML as displayed in the video title "Dynamically Display HTML with a Loop"?

Running the below Javascript always produces a blank, blue screen. Instead, it should produce a row of white dots numbered one through ten with a number displayed in each dot.

This isn't the first time this has happened. In fact, it happens EVERY TIME I run Javascript code designed to interact with HTML code in one of the Javascript lessons. By the way, I'm running Windows 11 with the latest version of Chrome.

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>JavaScript Loops</title>
    <link href="css/style.css" rel="stylesheet"> 
  </head>
  <body>
    <main></main>
    <script src="js/html-loop.js"></script>
  </body>
</html>```

```Javascript
const main = document.querySelector('main');
let html = '';

for ( let i = 0; i < 10; i++ ) {
  html += `<div>${i}</div>`;
}

main.innterHTML = html;```

1 Answer

Try changing main.innterHTML = html; to main.innerHTML = html;

That worked. Thanks.