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 trial

JavaScript JavaScript Loops Simplify Repetitive Tasks with Loops Create a do...while loop

They keep on giving me an error saying that i is an invalid variable. Please help.

let secret = ''; do{ let secret = prompt("What is the secret password?"); i++; } while(password !== 'sasame')

script.js
// Display the prompt dialogue while the value assigned to `secret` is not equal to "sesame"
let secret = '';
do{
  let secret = prompt("What is the secret password?");
  i++;
} while(password !== 'sasame')
// This should run after the loop is done executing
alert("You know the secret password. Welcome!");

6 Answers

Mark Casavantes
Mark Casavantes
10,619 Points

Good Morning Moukim and Serena,

You are correct Moukim. I assume Serena wanted to keep track of how many guesses took place. Since she is keeping track, the program should print out how many guesses were used or delete this variable.

Thank you,

Mark

you are not using the i variable why u incrementing its value

Mark Casavantes
Mark Casavantes
10,619 Points

Good Morning Serena,

Try putting "var" in front of your first instance of variable i. You can also use let i = 0; I hope this solves your problem.

Thank you,

Mark

Hey Serena,

There are a few errors in your code. First we can initialize the 'secret' variable to be empty:

let secret;

In the do while loop, you don't need to declare the 'secret' variable with the 'let' keyword as this has already been declared. Also there is no 'i' variable in this challenge and nothing to be counted, therefore is not needed. 'Sesame' is also misspelled in your code.

// Display the prompt dialogue while the value assigned to `secret` is not equal to "sesame"
let secret;

// This should run after the loop is done executing
alert("You know the secret password. Welcome!");

do {
  secret = prompt("What is the secret password?");
} while ( secret !== "sesame" );

Hope this helps. :)

Thank you everyone for your input! I appreciate it!