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 trialKalkidan Ashenafi
Full Stack JavaScript Techdegree Student 388 Pointscan't finish this code, it's an html file, how come it isn't accepting <p> or <h1>?
how can i display message on webpage using <script> tag?
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JavaScript Basics</title>
</head>
<body>
</body>
<script>
// Write your code here.
var div = document.getElementById("textDiv");
div.textContent = "Welcome to my site";
var text = div.textContent;
</script>
</html>
3 Answers
Larry Coonrod
5,041 PointsYou are making it way more complicated than what the challenge is asking for:
<script> // Write your code here.
document.write("Welcome to my site");
</script>
Ashley New
12,036 Points<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html"; charset="UTF-8"> <title>JavaScript Basics</title> </head>
<body>
<div id="textDiv"></div>
<script>
// Write your code here.
var div = document.getElementById("textDiv");
div.textContent = "Welcome to my site";
var text = div.textContent;
</script>
</body>
</html>```
You need to include the div you want to target. Also check your meta tag for errors.
Benjie Kibblewhite
9,323 PointsThis challenge wants you to use document.write() to get to your answer.
If the challenge did let you answer in another way and you wanted to use code like you have above, your code would need to include a div with the id 'textDiv' in the body tag so you could use the '.getElementById' method.