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

Kevin Lewis
seal-mask
.a{fill-rule:evenodd;}techdegree
Kevin Lewis
Front End Web Development Techdegree Student 9,667 Points

Syntax error

Not sure what I'm missing from this statement.

script.js
var a = 10;
var b = 20;
var c = 30;
if ("var a > var b"){ 
  window.alert("a is greater than b")
} else {
  window.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>

2 Answers

Hey Kevin. The challenge wants us to put an alert up, depending on if a is greater than b. It seems everything you input is correct except the condition. Since it is a condition, we cannot use double quotes because that would make it a string. Also, since we already declared a & b as variables, we don't need to use the "var" keyword again. The code should look something like this:

if (a > b) {

window.alert("a is greater than b")

} else {

window.alert("a is not greater than b")

}

Hope this helped.

Hi Kevin,

The mistake is coming from this row: if ("var a > var b")

In an 'if' statement you don't have to use "" and when you have declared variables "a" and "b", you should use them without the 'var' keyword. The 'var' keyword is used once - only when the variable is declared.

You should have something like this: var a = 10; var b = 20; var c = 30; if (a > b){ window.alert("a is greater than b"); } else { window.alert("a is not greater than b") ; }

*Advise: Put ';' at the end of you statements (In this case after the 'alert' function)