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

Godfrey M
PLUS
Godfrey M
Courses Plus Student 2,696 Points

about javascript prompt

why is it that when i create my function of targeting visitors name for example , the code works well but the website content will be hidden instead this is tricky can some one help me here?? var message = prompt("tell me your name please"); alert(message); console.log(message);

Tell me more about the website content! What do you mean? Did you cannot see the prompts or alerts?

2 Answers

Steven Parker
Steven Parker
231,275 Points

You'll need to wait on the page content to be fully loaded before you run your script. This might help:

window.onload = function() {
  var message = prompt("tell me your name please");
  alert(message);
  console.log(message);
};
Andrew Booth
Andrew Booth
1,578 Points

Unfortunately, I don't think he was talking about actual functions, for our course teacher has not discussed this with us yet at this part. However, the teacher has discussed with us that you may refer to alert as a function, so, here's how I did the simple way:

var Please_Give_Me_Name = prompt("What is your name? Please don't tell me it's Billy Joe..."); // Asks on web page
var Billy_Joe = alert(Please_Give_Me_Name); // Put in Billy Joe, outputs Billy Joe.

If there is ever a time where you feel that JavaScript is too hard or complicated, just remember this: all languages, no matter how big or small, are complicated. Focus on the easy bits.

If you ever need any help, I'm always here.