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

Louisa Guise
Louisa Guise
3,453 Points

I followed the video and am seeing nothing in the preview

var html = '';

for (var i = 1; i <= 10; i += 1;) {

html += '<div>' + i + '</div>'; } document.write(html);

2 Answers

Marcus Mayorga
Marcus Mayorga
5,863 Points

You have a semicolon in the last expression (i += 1;). Only the first two need it to separate the expressions. Get rid of that one right before the closing parentheses and you're good.

var html = '';

for (var i = 1; i <= 10; i += 1) {
html += '<div>' + i + '</div>'; 
} 
document.write(html);
Mathew Tran
PRO
Mathew Tran
Pro Student 10,096 Points

Did you save the file before previewing the page?

Hope this helps!

Matt