最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Syntax error - Logical if statement - Stack Overflow

programmeradmin2浏览0评论

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
Add a ment  | 

3 Answers 3

Reset to default 8

Put 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)) {... }
发布评论

评论列表(0)

  1. 暂无评论