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 trialGodfrey M
Courses Plus Student 2,696 Pointsabout 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);
2 Answers
Steven Parker
231,236 PointsYou'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
1,578 PointsUnfortunately, 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.
samuel dantas
447 Pointssamuel dantas
447 PointsTell me more about the website content! What do you mean? Did you cannot see the prompts or alerts?