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 trialMohamed Sheikh
2,306 PointsDon'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?
Mohamed Sheikh
2,306 PointsHello 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
Robert Richey
Courses Plus Student 16,352 PointsHi Mohamed,
Your code works fine for me, but it must be wrapped by script tags.
Mohamed Sheikh
2,306 PointsDo you mean the script tag that is inserted in the html page? If so, I have it there.
Robert Richey
Courses Plus Student 16,352 PointsAre 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
2,306 PointsI 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>
Robert Richey
Courses Plus Student 16,352 PointsI 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>
Robert Richey
Courses Plus Student 16,352 Pointsis 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
2,306 PointsI 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
Robert Richey
Courses Plus Student 16,352 PointsTry 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
Mohamed Sheikh
2,306 PointsWill do, thanks!
Raymond Osier
16,581 Pointsmohamed 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>");
Mohamed Sheikh
2,306 PointsThanks. It worked!
Nicolás Melgarejo
14,265 Pointsvar 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"); }
Dave McFarland
Treehouse TeacherDave McFarland
Treehouse TeacherHi Mohamed Sheikh
When this runs are you typing
Ruby
-- with the uppercaseR
. JavaScript is case sensitive soruby
isn't the same asRuby
.If that's not the case, then can you let us know what browser and operating system you're using.