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 Using Comparison Operators

I don't know what else to try based on the error message I'm getting

Bummer! There was an error with your code: TypeError: 'undefined' is not an object (evaluating 'alert._args[0][0].toUpperCase')

script.js
var a = 10;
var b = 20;
var c = 30;
if (a > b){
  alert(document.write('a is greater than b'));
} else {
  alert(document.write('a is not greater than b')); 
}                  
index.html
<!DOCTYPE HTML>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>JavaScript Basics</title>
</head>
<body>
<script src="script.js"></script>
</body>
</html>

1 Answer

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,860 Points

Hey TImothy,

You are on the right track and pretty much correct, except you have some code in there that doesn't belong (document.write). I'm not sure why you have that in there. The challenge wants an Alert box to pop up with the message. document.write is used more when you are injecting into HTML.

Have a look at the corrected code below:

var a = 10;
var b = 20;
var c = 30;
if (a > b) {
  alert('a is greater than b');
} else {
  alert('a is not greater than b'); 
}

Hope it makes sense. :)

:dizzy:

Thanks for the help, I put it in there because that's how it shows how to do it in the course.

Jason Anders
Jason Anders
Treehouse Moderator 145,860 Points

I see. :)

Often though, the course will show a couple different things, and then the challenges will change things up a bit to see if the concepts are being understood, instead of just copying the code from the lessons ... and sometimes they are really close.

Just to help clarify, alert() and document.write() are two very different methods, and could not be used together like you had even if you wanted to. alert() is the JS method that will create a pop-up dialog box with whatever message you include in the parameters. E.g. alert("This box wasn't here before") will create a pop up with that message.

document.write() will actually inject HTML into the style sheet as it renders. E.g. document.write("<p>This paragraph will appear on the webpage.</p>" So, when the page renders, this paragraph will show up on the webpage and not a pop-up box.

I hope this helps. :smiley: