Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Start a free Courses trial
to watch this video
Use the `while` statement to create a loop that executes code as long as a condition evaluates to true.
Reminder
The value of a variable declared with const
cannot be changed through reassignment. We're using the addition assignment operator (+=
) to add one to the current value of counter
, until it reaches the value 10
.
let counter = 0;
while ( counter < 10 ) {
console.log( getRandomNumber(10) );
counter += 1;
}
In this case, it's important to use the keyword let
, which, as you learned, lets you change (or manipulate) a variable's value through reassignment.
Resources
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
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