Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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!