意外的标记'('在多个表达式语句上

时间:2014-04-04 04:57:16

标签: javascript jquery if-statement

试图在W3Schools上显示if语句,但我的浏览器似乎抛出错误Uncaught SyntaxError: Unexpected token (第二个if语句是有问题的:if ( newbalance > 0 || newincome > 0 ) || ( newbalance > 0 && newincome > 0 ) {

全功能

    // Start inverval
    function ticker(p) {

        var newbalance = 0;
        var newincome = 0;

        if ( p == true ) {

            if ( newbalance > 0 || newincome > 0 ) || ( newbalance > 0 && newincome > 0 ) {
                newbalance = ( newbalance + 1 );
            } else {
                newbalance = ( rmoney.balance + 1 );
            }

            $('.balancec').html('$' + formatMoney(newbalance, 2));

        } else {

            if ( btrigger.taxhike ) {
                var ticker = setTimeout(function(){
                    if ( newbalance > 0 && newincome > 0 ) {
                        newbalance = ( newbalance + boosts.taxhike ),
                        newincome = ( newincome + boosts.taxhike );
                    } else {
                        newbalance = ( newbalance + boosts.taxhike ),
                        newincome = ( newincome + boosts.taxhike );
                    }
                    $('.balancec').html('$' + formatMoney(newbalance, 2));
                    $('.incomec').html('+$' + formatMoney(newincome, 2) + '/ps');

                });
            }
            if ( btrigger.raisepay ) {
                var ticker = setTimeout(function(){
                    if ( newbalance > 0 && newincome > 0 ) {
                        newbalance = ( newbalance + boosts.raisepay ),
                        newincome = ( newincome + boosts.raisepay );
                    } else {
                        newbalance = ( newbalance + boosts.raisepay ),
                        newincome = ( newincome + boosts.raisepay );
                    }
                    $('.balancec').html('$' + formatMoney(newbalance, 2));
                    $('.incomec').html('+$' + formatMoney(newincome, 2) + '/ps');
                });
            }

        }

    }

5 个答案:

答案 0 :(得分:3)

这里缺少括号,

if (( newbalance > 0 || newincome > 0 ) || ( newbalance > 0 && newincome > 0 )){
---^  ------------------------------------------------------------------------^

if语句的基本语法是

if(condition){
  code block
}

但是您使用的语法类似于

if condition {
  code block
}

答案 1 :(得分:1)

(语句打开)并关闭if括号,您有if()()而不是if(()())外套缺少。

更改

if ( newbalance > 0 || newincome > 0 ) || ( newbalance > 0 && newincome > 0 ) {

if (( newbalance > 0 || newincome > 0 ) || ( newbalance > 0 && newincome > 0 ) ){

答案 2 :(得分:1)

您缺少打开和关闭的括号

if ( (newbalance > 0 || newincome > 0 ) || ( newbalance > 0 && newincome > 0 )) {

答案 3 :(得分:1)

// Start inverval
function ticker(p) {

  var newbalance = 0;
  var newincome = 0;

  if ( p == true ) {

    if (( newbalance > 0 || newincome > 0 ) || ( newbalance > 0 && newincome > 0 ) {
      newbalance = ( newbalance + 1 );
    } else {
      newbalance = ( rmoney.balance + 1 );
    }

    $('.balancec').html('$' + formatMoney(newbalance, 2));

  } else {

    if ( btrigger.taxhike ) {
      var ticker = setTimeout(function(){
        if ( newbalance > 0 && newincome > 0 ) {
          newbalance = ( newbalance + boosts.taxhike ),
            newincome = ( newincome + boosts.taxhike );
        } else {
          newbalance = ( newbalance + boosts.taxhike ),
            newincome = ( newincome + boosts.taxhike );
        }
        $('.balancec').html('$' + formatMoney(newbalance, 2));
        $('.incomec').html('+$' + formatMoney(newincome, 2) + '/ps');

      });
    }
    if ( btrigger.raisepay ) {
      var ticker = setTimeout(function(){
        if ( newbalance > 0 && newincome > 0 ) {
          newbalance = ( newbalance + boosts.raisepay ),
            newincome = ( newincome + boosts.raisepay );
        } else {
          newbalance = ( newbalance + boosts.raisepay ),
            newincome = ( newincome + boosts.raisepay );
        }
        $('.balancec').html('$' + formatMoney(newbalance, 2));
        $('.incomec').html('+$' + formatMoney(newincome, 2) + '/ps');
      });
    }

  }

}

使用这个你想念“(”在你的代码中

答案 4 :(得分:1)

看起来你的功能是正确的但是如果条件

就结束了
       if ( newbalance > 0 || newincome > 0 ) || ( newbalance > 0 && newincome > 0 ) {

}

您需要将if条件更改为..

    if (( newbalance > 0 || newincome > 0 ) || ( newbalance > 0 && newincome > 0 )){
}

如何使用逻辑鸦片

例如

鉴于x = 6且y = 3,下表解释了逻辑运算符:

Operator      Description                                Example
&&                and                         (x < 10 && y > 1) is true
||                or                          (x==5 || y==5) is false
!                 not                         !(x==y) is true