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

sean farrelly
sean farrelly
1,614 Points

add a conditional statement that tests if the value in variable a is greater than the variable b. if it is a pop up aler

add a conditional statement that test if the value in variable a is greater than the variable b. if it is a pop up alert with message a is greater than b. also add is greater else clause that pops up the message a is not greater than b.

var a = 10;
var b = 20;
var c = 30;
if (" answer === " var a" > " var b ") {
     windows.alert ("var a is greater than var b") ;
} else { 
  windows.alert ( " var a is not greater than var b");
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>JavaScript Basics</title>
<script src="script.js"></script>

2 Answers

Steven Parker
Steven Parker
229,982 Points

First off, your conditional statement looks like you're trying to format a string for printing ... but to actually compare two variables you only need their names and the comparison operator. In this case :point_right: (a > b)

Then, when you print your alerts, your strings are a bit different than what the challenge asked. They need to be exactly the same for the checking routine to recognize them.

And finally, you wrote "windows" (with an extra "s") instead of "window" when calling the alert. You can fix it, but if you want you can also remove it entirely since the properties and methods of the window object are accessible just by name.

Steven Parker
Steven Parker
229,982 Points

While that code may get a "pass" from the checking routine, that's actually not what the challenge asks for, for some of the reasons I discussed in my hints. The solution based on the instructions is actually a bit simpler (hint: no concatenation is needed).

Plus I think most folks get a better learning experience arriving at the final code themselves instead of plugging in explicit code solutions.

But your desire to help is great. Please take my comments merely as suggestions.