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

R R
R R
1,570 Points

Challenge tells me it can't see the else statement but the code runs and I'm not seeing any errors

here is my code;

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);

}

script.js
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);

}
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>

5 Answers

William Li
PLUS
William Li
Courses Plus Student 26,868 Points

i think the code is asking you to do is simply this:

if (a>b) {
  alert("a is greater than b"); 
} else {
  alert("a is not greater than b");
}

You don't need to do string concatenation

Hi. your code works properly. Look: JSFiddle

R R
R R
1,570 Points

I thought it worked fine too but I keep getting the same error message. Looked up "alert" in MDN and was led to a page with the headline "archive of obsolete content." Maybe that's why I'm getting the error? And, i didn't know about JSFiddle. That looks very useful. Thank you!

Link below leads to MDN:

https://developer.mozilla.org/en-US/docs/Archive/Mozilla/XPInstall/Reference/Install_Object/Methods/alert

R R
R R
1,570 Points

Oh. Well, geez. I was making it more complicated. That's so like me.

Dave McFarland
Dave McFarland
Treehouse Teacher

Sorry! You had a perfectly good (even better) answer than I was looking for. I'll edit the code challenge to work for your answer as well.

R R
R R
1,570 Points

oh wow, really? You just made this noob's day! Wish i could say it was skill. Lol.