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 trialGiovanni Chiaro
1,762 PointsValue and Variables with Alert command
Why in the video he put this
Var visitorname =prompt (“What is your name ? “ ); alert (visitorname);
and why in the alter command he didn't execute like this alert("visitorname"); With the Quotes Marks .
1 Answer
Valeshan Naidoo
27,008 PointsSo first, lets clean up the code a little
var visitorName =prompt("What is your name?");
alert(visitorName);
To answer your question, visitorname has been declared a variable. You can therefore place this declared variable inside the alert method. If you were to use :
alert("visitorName");
It would return the string "visitorName". But that's not what we want.
In the visitorName variable, a prompt method is used which asks the user for their name ("What is our name?"). The response that is inputted into the text box is then saved into the variable visitorName.
Now when the alert function that has visitorName is called, it will bring up the content of visitorName, which is the name of the user.