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, Arrays and Objects Simplify Repetitive Tasks with Loops Create a `do...while` loop

Ronald Ashby
Ronald Ashby
2,878 Points

Corrupt Challenge: no correct code answer for the do ...while (secret) challenge.

Declared var secret; first, and placed prompt in while loop and the do...while fails. Works fine offline in text editor.

var secret;
do {
  secret = prompt("What is the secret password?");   
} while ( secret !== "sesame" );
document.write("You know the secret password. Welcome.");
script.js
var secret = prompt("What is the secret password?");
while ( secret !== "sesame" ) {
  secret = prompt("What is the secret password?");    
}
document.write("You know the secret password. Welcome.");
index.html
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>JavaScript Loops</title>
</head>
<body>
<script src="script.js"></script>
</body>
</html>
Ronald Ashby
Ronald Ashby
2,878 Points

Thanks! That's the first challenge I've had where you replace the pre-loaded code.

4 Answers

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,858 Points

Hey Ronald,

I added markdown to the first part of the code you posted so it can be read. It looks like xela888 didn't see this, as your code is correct and is exactly what the challenge asked for.

I copied and pasted the first snippet that you already had written and it passed the challenge. So, it may have just been a glitch in the challenge. If you haven't passed it yet, just copy your code snippet into (and overwriting) the pre-loaded code of the challenge, and you're good to go. Keep Coding! :dizzy:

This code works, but this challenge is asking you to replace the while loop into a do-while loop. You should review the video, but if you just want the answer now, here:

var secret;

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

document.write("You know the secret password. Welcome.");

Please review the video to learn the difference (because I don't want to waste time on this, I want to help more people)

Hope it helps! ~xela888

Ronald Ashby
Ronald Ashby
2,878 Points

Thanks! First challenge I've had where you replace the pre-loaded code.