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) Introducing JavaScript Your First JavaScript Program

I'm not sure what I'm doing wrong. I've tried alert() and document.write(). Neither are working for me unfortunately.

I'm sure it's a simple problem that I'm just not seeing. Thank you for the help!

index.html
<!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.
  document.write('Welcome to my website');
</script>

</html>

2 Answers

Hi Lemuel,

First off, just to let you know, there is no problem with the quotes you are using. You can use single or double quotes if you wish. The only problem you have is that you have "website" instead of "site". So, as soon as you change that, your challenge will pass! :)

document.write('Welcome to my site');

you need to use "" instead of ''

so it's

document.write("Welcome to my site");

The first part of your answer is incorrect. You can use either double quotes or single quotes. The problem is that the string they want you to write is "Welcome to my site" (as you put) but Lemuel has "Welcome to my website" and that is causing the challenge to give a bummer output.

The example the instructor gave in the video preceding the code challenge had double quotes in it so I assumed you would need to use double quotes. He did not specify that you can write javascript in double or singles.

Regardless. The answer I typed in did give a correct answer but thanks for pointing that out for anyone who has the same issue.

You absolutely can write strings in JavaScript using either a set of double quotes or a set of single quotes. In fact, there are more than a few ways to do so. The reason why your answer was correct was because of the text content itself, not the quotes surrounding the content.

There's more than a few ways to pass this challenge:

//all of these are valid code and will pass the challenge
document.write("Welcome to my site");
document.write('Welcome to my site');
//double quotes outside, single inside
document.write("'Welcome to my site'");
//single quotes outside, double inside
document.write('"Welcome to my site"');
//using the String function to pass a string using either double or single quotes
document.write(String("Welcome to my site"));
//and more than likely more ways that I'm forgetting at the moment