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 trialR R
1,570 PointsChallenge 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);
}
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);
}
<!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
Courses Plus Student 26,868 Pointsi 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
Michal Martinek
Courses Plus Student 476 PointsHi. your code works properly. Look: JSFiddle
R R
1,570 PointsI 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:
R R
1,570 PointsOh. Well, geez. I was making it more complicated. That's so like me.
Dave McFarland
Treehouse TeacherSorry! 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
1,570 Pointsoh wow, really? You just made this noob's day! Wish i could say it was skill. Lol.