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 Quickstart Data Types and Variables Use Variables to Display Different Content

Prompt example in this video asks "What is your name?" Twice is my browser.

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

var response=prompt(question); alert("Hi " + response + "!");

2 Answers

Aakash Srivastava
Aakash Srivastava
5,415 Points

Hey friend STEVEN AGUILAR , it's because you are calling prompt(question) twice .
First , you are calling it independently and then you are calling it again and assigning its response to the variable response .
Remember , you need to call it only once . Here is the improved code :

var question = "What is your name?";

var response = prompt(question);  // First prompt(question) will be called then it's value will get assigned into response variable
alert("Hi " + response + "!");

Hope it helped :)

Thank you for pointing that out!