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!
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

Sukhraj Grewal
10,554 PointsCode doesn't do what i expected it to do
for ( var counter = 5; counter; counter = counter -1) {
alert("Hello WOrld", counter);
}
This suppose to alert Hello world with counter at the end 10 times and every time counter gets - 1 .
But after i run this code this alerts hello world 10 times but doesn't display the counter
Any Help ?
3 Answers

Sean T. Unwin
28,688 Pointsalert()
takes only 1 argument. If you want to see counter
displayed use the following format:
alert("Hello World " + counter);
console.log()
, which is used in the video, does take comma separated objects to be output:
console.log("Hello World", counter);

Bryan Jenkins
5,438 PointsTry this out. Javascript uses the + symbol to concatenate a string.
for (var counter=5; counter; counter--) {
alert("Hello World " + counter);
}

Sukhraj Grewal
10,554 PointsThanks