1

I am going to try and do this as best as I can.

var myPrompt = prompt("Are you ready to go?");

if myPrompt == true {

console.log("Great, let's go.")

} else {

console.log("Hurry up, we don't have all night.")

};

The question is HOW do I pass the value from the above INTO a Boolean function that will do a while loop in the process?

I need to take the boolean value from the above and pass it along into a function that does a Boolean comparison against any other value. As the two are compared, I am doing a while loop until the comparison is satisfied.

illstaygold
  • 15
  • 1
  • 5
  • so you stated what you are intending to do...what's not working and where is the code for it? – charlietfl Jul 18 '14 at 00:26
  • Well, the issue for me is the syntax behind it. I have been typing for a solid hour and not getting any results. – illstaygold Jul 18 '14 at 00:27
  • @illstaygold I've updated my answer I'm not sure how the myPrompt variable ties into the rest of your code. If its unnecessary see my second code snippet which is functionally equivalent to the first. – t3dodson Jul 18 '14 at 01:50

1 Answers1

0

Check this answer How to create a dialog with “yes” and “no” options?

the confirm function returns a boolean.

To get an infinite loop prompting the user to say yes USING A VARIABLE try

var response;
//while the user has NOT confirmed he is ready to go
while(!(response = confirm("Are you ready to go?"))){
    alert("hurry up");
}
//the user is ready to go.

EDIT ** This code is much better style than the first snippet if it will suffice. Note that you dont actually need the variable to get the code working the following is cleaner

//you can glean the state of the user response without a variable
while(!confirm("Are you ready to go?")){
    alert("hurry up");
    //process not ready state
}
alert("Lets GO!");
Community
  • 1
  • 1
t3dodson
  • 3,949
  • 2
  • 29
  • 40