Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Well done!
You have completed Practice JavaScript Loops!
You have completed Practice JavaScript Loops!
Preview
Learn one possible solution for tracking guess attempts and displaying the number of attempts on the page.
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
Back in my program, I'll declare
a new variable named attempts and
0:00
set it to 0 initially.
0:03
Then down in the do block,
I'll increase the value of
0:06
attempts by 1 each time
it runs with attempts++.
0:11
I'm using the increment operator to add 1
to the current number value stored in
0:16
attempts each time the loop runs.
0:20
It's totally fine if you use the addition
assignment operator here too.
0:23
This works exactly the same.
0:26
Outside of the loop,
within the template literal,
0:28
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up