Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript JavaScript Basics Making Decisions in Your Code with Conditional Statements Use Comparison Operators

Thought I did this correctly as well? Apparently not?

if (answer === "a > b");
{ console.log("That's correct")
else {
console.log("a < b")
const a = 10;
const b = 20;
const c = 30;
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>JavaScript Basics</title>
<script src="script.js"></script>

1 Answer

Cameron Childres
Cameron Childres
Treehouse Moderator 11,715 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.