I`m just using a If statement with the logical operator. I dont know why it is showing sytax error.
var divWidth = $("#columnwraper").width(); //getting the width of the div
$("#right-button").click(function() {
if (cursor != totalWidth && totalWidth !< divWidth) {
$box2.animate({
marginLeft : "-=300"
}, "fast");
cursor += 100;
}
// console.log(colwidth.width());
});
It`s showing that
[15:18:24.050] SyntaxError: missing ) after condition.
What am I doing wrong here?
I`m just using a If statement with the logical operator. I dont know why it is showing sytax error.
var divWidth = $("#columnwraper").width(); //getting the width of the div
$("#right-button").click(function() {
if (cursor != totalWidth && totalWidth !< divWidth) {
$box2.animate({
marginLeft : "-=300"
}, "fast");
cursor += 100;
}
// console.log(colwidth.width());
});
It`s showing that
[15:18:24.050] SyntaxError: missing ) after condition.
What am I doing wrong here?
Share Improve this question edited Jun 27, 2013 at 12:33 Justin 86.9k49 gold badges230 silver badges371 bronze badges asked Jun 27, 2013 at 9:54 AshAsh 2372 gold badges9 silver badges25 bronze badges 4-
2
What is
!<
operator? Why you don't use>=
instead? – Petr R. Commented Jun 27, 2013 at 9:56 -
3
Note that
!=
is one operator. It is not a bination of!
and==
. You cannot simply bine!
with other operators (i.e.!<
is invalid). – Felix Kling Commented Jun 27, 2013 at 9:58 - @FelixKling Noted felix. Thank you. – Ash Commented Jun 27, 2013 at 10:04
- No idea why this is being voted to close - this question is fine and has a valid accepted answer – Justin Commented Jun 27, 2013 at 12:34
3 Answers
Reset to default 8Put it this way:
if (cursor != totalWidth && !(totalWidth < divWidth))
!<
is not an operator.
Error in totalWidth !< divWidth
Should be totalWidth < divWidth
or totalWidth >= divWidth
Always put logical operators in inner brackets for operations like: (totalWidth < divWidth)
And !<
is not an operator.
You should use this:
if ((cursor != totalWidth) && !(totalWidth < divWidth)) {... }