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!

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 Basics (Retired) Storing and Tracking Information with Variables Capturing Visitor Input

Immanuel Jaeggi
Immanuel Jaeggi
5,164 Points

Somethings are not fully understandable in this video

I understood that the prompt("What`s your name"); gets visitors to type their name in, and that the variable visitorName stores only their name.

In this case, the following code will first prompt the user for their name, then display their name in the alert box.

var visitorName = prompt("What is your name?"); alert(visitorName);

My question is, why would they want to see their name again just after typing it in?

And why would I want to use the console.log to see the user`s name in the JS console?


4 Answers

Max Senden
Max Senden
23,177 Points

Hi Immanuel,

These are just exercises for you to get acquainted with writing Javascript and how to apply it on your webpage. The console is a good place for you to see whether or not your Javascript is working, and if not, to give you a clue where to look in order to fix it.

Max Senden I wanted to ask on 1:50 the instructor said something I didn't quite catch, something about a variable returning a value I don't understand what he meant and Im curious??

@Lucas Leniek he said that the prompt command returns a value, which is whatever the person type in the prompt that appears when the command runs. This value needs to go somewhere, so we store it inside of a variable. In other words, we program a variable to receive whatever the person types in the prompt thing. Hope it helps.