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 trialRonnie Richardson
3,599 PointsSyntax Error: Parse Error?
I can't figure out exactly what is the error in this code. The syntax appears to be correct to me but I continue to get this "error" message. Please help.
var a = 10;
var b = 20;
var c = 30;
if (var a > var 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>
2 Answers
Marcus Parsons
15,719 PointsHey Ronnie,
There is one main problem with your code and that is the comparison statement var a > var b
. You don't want to use the var keyword after the variable has already been created. You only want to use that keyword when first creating the variable. Once its created, just access the variable by name like a
or b
.
Also, there is another problem that wouldn't invalidate your code, but when it comes to challenges, try to stick to the script they give you. If they give you a string to output, be sure to copy that exact string. For example, in the challenge it is "a is greater than b" and in the else it is "a is not greater than b" like that. I like your way, too, Ronnie, but the Challenges are very particular about what they accept for an answer.
if (a > b){
alert('a is greater than b');
} else {
alert('a is not greater than b');
}
Ronnie Richardson
3,599 PointsThank you so much for that information Marcus Parsons!!!
Marcus Parsons
15,719 PointsYou're very welcome, Ronnie! Happy Coding :)