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

marcus smith
marcus smith
2,576 Points

I don't know where to even begin... I have been thru the videos a few times now....

This course is nothing but F- for me...

script.js
var secret = prompt("What is the secret password?");  // don't need this; just create var secret
do {
  secret("what is the secret password?"); // this needs to be a prompt, as above

}
while ( secret !== "sesame" ) { // SO close! End the loop here with a ;
  secret = prompt("What is the secret password?");    // not needed
}  // not needed
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>

6 Answers

Steven Parker
Steven Parker
229,732 Points

You've got most of the parts there, but a few issues remain:

  • you don't need to assign secret when you declare it anymore
  • when you do assign it, don't try to call it like a function
  • the block following the while is not part of a do...while

It might be a bit clearer if I comment directly in your code:

var secret/* = prompt("What is the secret password?")*/; // assignment not needed here anymore
do {
  secret("what is the secret password?");                // ASSIGN secret (using "prompt") here
}
while ( secret !== "sesame" )/* {                        // this is not part of a "do...while"
  secret = prompt("What is the secret password?");       // this is what needs to be done above
}*/
document.write("You know the secret password. Welcome.");

Shame on any MODs posting explicit spoilers! :disappointed:

And may the course continue to be nothing but FUN for you. (I'm sure that's what you meant) :wink:

Hi Steven,

I don't see that there's any shame in trying to help someone who appears to be struggling and is asking for assistance - the Moderators are here to help; not hinder. Directly answering questions is my style but I will always include an explanation for my answer, as above.

Regards,

Steve.

Steven Parker
Steven Parker
229,732 Points

Steve, you should be aware that giving someone an answer is not as helpful to learning as assisting them to arrive at their own solution.

And take another look at your copy of the moderator guidelines document.

Hi Steven,

I guess learning styles, and answering styles, are specific to each individual - direct answers with no explanation are unconstructive, I will absoutely agree. But providing an explanation along with some completed, working code reiterates what was presented in the videos which can reinforce the learning gained from the teacher.

I can't tell the best learning style of each person posting within the Community Pages so I try to help everyone, where I am able, reach a solution by answering their questions coupled with an explanation of the reasoning behind my approach.

All the best,

Steve.

marcus smith
marcus smith
2,576 Points

Thanks for the help. I suppose this is where I should just stop treehouse. Javascrip is making absolutely no sense.

Hi Marcus,

Don't give up! You were pretty close to the solution here, so you're clearly doing well, and if it's all still new to you, it can take a while for the concepts to sink in. I know I need to have gone over new concepts a number of times before I'm anywhere near to understanding them.

Maybe take a break from JavaScript and try something else for a while. Then come back and see if it comes more easily to you. Alternatively, carry on with the videos and keep asking for help in the forum - there's lots of people willing, able and happy to help you out. Gaining different explanations of the key concepts can help build the foundations of good knowledge.

Steve.

Steven Parker
Steven Parker
229,732 Points

I agree with not giving up, and taking a break might not be a bad idea either.

But ... did you start out with this course? Or did you take Javascript Basics first? If you didn't, I definitely recommend setting this one aside and doing that one first.

marcus smith
marcus smith
2,576 Points

I am already at yet another failing quiz.... This is not fun at all.

JavaScript isn't my strongest suit - Steven's more adept at it - but give us a link to the quiz, and we'll have a go at explaining the solution to you.

Steve.

marcus smith
marcus smith
2,576 Points

I signed up on this site only because I wanted to be able to develop apps and not just websites. 15 years I have been developing websites and stupid emails for many of companies. So I follow along with the step by steps.... Dave makes it seem so easy yet every code challenge something goes completely wrong. EXTREMELY and TERRIBLY wrong.

Steven Parker
Steven Parker
229,732 Points

It sounds like frustration has become an obstacle in itself.

A little break is probably a good idea. And when you return, be sure to start with Javascript Basics if you haven't done that one already.

Hey, Marcus. I didn't see anything extremely or terribly wrong with your code at all. You've clearly taken a good amount in.

If you post a link to the challenge you're struggling with we can walk you through the solution and explain the basis of the code.

What kind of applications do you want to develop? Is it worth taking a break from Javascript and having a look at The Java or Android tracks? You'll cover a lot of the same concepts so the learning is totally transferable across different languages. Android is good fun!

Keep at it; you will get there - and keep asking questions in the Community pages.

Steve.

marcus smith
marcus smith
2,576 Points

I have already done that....

Hi Marcus,

You want to remove the initial prompt and just rely on the one inside the loop. Move the test to the end of the loop so it definitely runs once. Start with the do keyword:

var secret; 
do {
  secret = prompt("What is the secret password?");    
}while ( secret !== "sesame" );
document.write("You know the secret password. Welcome.");

We create the variable secret, then enter the loop. The user is prompted for a response and that response is stored in the variable and then tested against the password. If the two match, the loop stops. If they don't it loops, re-prompting the user for their input.

I hope that makes sense.

Steve.

I added a few pointers in your code too. You were pretty close to nailing that!