Ash
Ash

Reputation: 237

Syntax error - Logical if statement

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?

Upvotes: 1

Views: 1078

Answers (3)

Manish Doshi
Manish Doshi

Reputation: 1193

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)) {... }

Upvotes: 1

Rohan Kumar
Rohan Kumar

Reputation: 40639

Error in totalWidth !< divWidth

Should be totalWidth < divWidth or totalWidth >= divWidth

Upvotes: 2

Teemu
Teemu

Reputation: 23406

Put it this way:

if (cursor != totalWidth && !(totalWidth < divWidth))

!< is not an operator.

Upvotes: 8

Related Questions