JavaScript JavaScript Loops, Arrays and Objects Simplify Repetitive Tasks with Loops For Loops

yoav green
yoav green
8,611 Points

white screen when running the code

var html = '';

for (var i = 1; i <= 10; i+=1) { html += '<div>' + i + '</div>'; }

document.write(html);

why am i getting only a white screen?

Chris Troy
Chris Troy
Full Stack JavaScript Techdegree Student 7,390 Points

Okay, I was having the same thing happen and when I looked in the console it said that the .js file did not exist. How I fixed it was deleting my js folder and it's contents and created a new one. After that it worked perfectly, nothing is wrong with the code.

1 Answer

Balazs Pukli
Balazs Pukli
46,038 Points

Your code works just fine. Maybe you've forgot to reference the js file from index.html? You have to include, it's not enough to have it in the project folder.