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 trialJames Mockridge
4,043 PointsA note on the output of this loop.
const main = document.querySelector('main'); let html = '';
for (let i = 1; i <= 10; i++) { html += '<div>${i}</div>'; }
main.innerHTML = html;
I found the ${i} selector ended up evaluating to printing '${i}' many times rather than a sequence of numbers.
Instead I wrote the following and it evaluated to the desired result. I am unsure of why the former syntax didn't work.
const main = document.querySelector('main'); let html = '';
for (let i = 5; i <= 100; i+=5) { html += '<div>' + i + '</div>'; }
main.innerHTML = html;
1 Answer
Martin Sole
82,199 PointsWere you using quotation marks or back ticks?, they do look very similar, but the key for back ticks is usually found on the left hand side of the keyboard, at least on my computers they are (Mac to the left of Z and pc to the left of 1). Template literals require back ticks to be used in order to work, so ${i}
.
Adam N
70,280 PointsAdam N
70,280 PointsThose are single quotes in his code so you are correct.