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 Tracking Multiple Items with Arrays Useful Array Methods

So it's safe to say by now that when you use the "prompt" method in javascript, it automatically stores the input value?

I don't know if this was explained in a prior video, but it's important to note that you don't need a variable to store an input value when you have prompt, correct?

Thanks

Arikaturika Tumojenko
Arikaturika Tumojenko
8,897 Points

You need a variable to store an input when you have a prompt box. Otherwise the value is forever lost.

prompt("How many days are in a week?");

(The user types 7 and the number is not stored anywhere. You can't access this value and you can't use it later in your code.)

var weekDays = prompt("How many days are in a week?);

(The user types 7 and the number is stored in the weekDays variable. You can access its value and use it later in your code.)

1 Answer

Jason Williams
Jason Williams
6,691 Points

If you wish to use the input and recall it from memory then you'll need a variable to store it in or else you will have no way of accessing the data from memory to my knowledge.