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 Making Decisions in Your Code with Conditional Statements Use Comparison Operators

Thought I did this correctly as well? Apparently not?

script.js
if (answer === "a > b");
{ console.log("That's correct")
};
else {
console.log("a < b")
};
const a = 10;
const b = 20;
const c = 30;
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

Cameron Childres
Cameron Childres
11,817 Points

Hey Kamran,

Some notes on your answer:

if (answer === "a > b"); // conditional should only contain (a > b). Semicolon ends statement -- remove it.
{ console.log("That's correct") // Log the string given in the question
}; // Remove semicolon or statement ends here
else {
console.log("a < b") // Log the string given in the question
};
  • Inside if() is the condition to be evaluated. You want this to just be (a > b), as that will evaluate to true or false depending on the variables given to it. Right now you're saying "does the variable answer exactly equal the string "a > b". There is no variable answer, and a or b in quotes will not access the variables you have.
  • Semicolons are used to end statements. This is an if-then statement, so you don't want any semicolons separating its parts. You can have semicolons inside the curly brackets as that's code that runs after the condition is checked.
  • Challenges are often specific about answers they want produced. This challenge wants one of two strings logged: "a is greater than b" or "a is not greater than b". If they are not exact then it will not accept your answer.

Hope this helps! Let me know if you get stuck or have any questions.