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 trialstevesirman
7,518 PointsChallenge Task 4 of 4
Use the alert() function to display the contents of the message variable in a dialogue window.
const myName = 'Guil';
let myAge = 43;
var message = "What is your name";
prompt(message)
var response = prompt (message)
var message = "What is your age";
prompt(message)
var response = prompt (message)
alert ("What is your name" + response + "what is your age" + response);
1 Answer
Ryan Dudley
Treehouse Project ReviewerWhile it is good you are experimenting with the prompt()
method to retrieve the data from user input, I think that is what is causing the issue here. The task wants you to concatenate the myAge
and myName
variables into a simple string that is stored in message
. We then pass the message
variable to the alert function. So, for example:
var myName = "Guil";
var myAge = 48;
var message = myName + " is " + myAge;
alert(message);
NOTE: The code block below does not pertain to the challenge, as it does not accept the use of prompt()
. However, you could rewrite your original script to achieve the same effect using prompt()
(although this challenge will not accept it as a valid answer, this is just for your own personal knowledge):
var myName = prompt("What is your name?");
var myAge = prompt("What is your age?");
var message = myName + " is " + myAge;
alert(message);
Shaun Baxley
10,842 PointsShaun Baxley
10,842 PointsYou have multiple variables with the same name each "var" should have an unique name. alert(final message)
or try alert(message)