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) Making Decisions with Conditional Statements Introducing Conditional Statements

Mohamed Sheikh
Mohamed Sheikh
2,306 Points

Don't know why my document.write isn't showing up.

var answer = prompt('What programming language is the name of a gem?');
if ( answer === 'Ruby' ) {
    document.write("<p>That's right!</p>");
}

I've tried it on workspace and on notepad++ but the "That's right" message doesn't show up. Anything that I'm doing wrong?

Dave McFarland
Dave McFarland
Treehouse Teacher

Hi Mohamed Sheikh

When this runs are you typing Ruby -- with the uppercase R. JavaScript is case sensitive so ruby isn't the same as Ruby.

If that's not the case, then can you let us know what browser and operating system you're using.

Mohamed Sheikh
Mohamed Sheikh
2,306 Points

Hello Dave McFarland.

I changed the "R" in Ruby to a lower case "r" but nothing changed. I'm still not getting the message "that's Right." I'm using chrome in a windows 7 computer. I appreciate the help.

3 Answers

Hi Mohamed,

Your code works fine for me, but it must be wrapped by script tags.

Mohamed Sheikh
Mohamed Sheikh
2,306 Points

Do you mean the script tag that is inserted in the html page? If so, I have it there.

Are you doing this for the challenge or on your own, local machine? The challenge doesn't need script tags. Post your entire html file please.

Mohamed Sheikh
Mohamed Sheikh
2,306 Points

I was doing it via workspace. See html below

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <link rel="stylesheet" href="css/main.css">
  <title>A programming quiz</title>
 </head>
<body>
  <div class="container">
  <h1>A programming quiz</h1>
   <script src="quiz.js"></script> 
  </div>
</body>
</html>

I have a workspace with an index.html file and this code works for me.

<!DOCTYPE html>
<html>
<head>
<body>
  <script>
    var answer = prompt('What programming language is the name of a gem?');
    if ( answer === 'Ruby' ) {
      document.write("<p>That's right!</p>");
    }
  </script>
</body>
</head>
</html>

is quiz.js located in the same directory as the html file?

Edit: I created a quiz.js file in the same folder as index.html, copy pasted your code (but deleted the link to css) and everything works.

Mohamed Sheikh
Mohamed Sheikh
2,306 Points

I tried your method but the document.write message still didn't show up. So the code is written correctly, must be workspace then I guess. I appreciate you taking the time to help

Try creating a new workspace and selecting 'Front-End' environment. That's what I used. If you continue to have issues, it may be worth emailing support at

help@teamtreehouse.com

Raymond Osier
Raymond Osier
16,581 Points

mohamed sheikh Try adding this to your if statement this will help correct the case sensitive nature of JavaScript (when you type the answer in the prompt reguardless of how you type it "Ruby", "RUBY", or "ruby" it will right to the document) if (answer.toUpperCase() === 'RUBY' ) { document.write("<p>thats right!</p>");

Nicolás Melgarejo
Nicolás Melgarejo
14,265 Points

var answer = prompt("What programming language is the name of a gem");

if (answer.toUpperCase() === "RUBY") { document.write("<p>Excelent</p>"); }

else { document.write("Oh no! Let's try again"); }