Welcome to the Treehouse Community
Looking to learn something new?
Don Miller3,582 Points
var visitor = prompt (slight confusion)
When you initially use:
var visitor = prompt("What is your name?");
...and then later down the code you use:
var message = "Hello " + visitor .....
How and/or why does the prompt not appear again? Is this because the prompt already appeared, someone entered their name and now
var visitor will always be registered as the person's name (unless changed further down the code).
That's my only confusion right now. Why doesn't the prompt box continue to appear when using
var visitor when the purpose of
var visitor is literally to prompt? How does it know to stop prompting, I guess that's my question. lol
If I missed this in the video, that I've watched twice, please just tell me to watch the video again. :o)
Hey Donald! Good questions, and the confusion is understandable. At this stage of the game, don't worry too much about this piece not making a lot of sense. I think the point is to understand that you can store a users input from the
prompt() method in a variable and then use it later in your code. The reason it doesn't prompt again is because the prompt method, on it's own in the global scope of the program, only runs once on page load. You will start learning about loops and functions later on where you can prompt multiple times and even call a function to prompt a user multiple times throughout the code.
This confused me at first, too! Then I learned the prompt method returns whatever is typed into the box. So whatever is typed gets stored in the variable. Then the program moves on and runs the next line.