Cool Guy Yo
Cool Guy Yo

Reputation: 6120

more than 2 or operators in a if statement

I want to use more than two || operators inside of a if statement, however if I add in a third || operator the code stops working. I must be doing it wrong. Some help with an explanation would be great. Here is a link to the working file without the third || http://jsfiddle.net/anderskitson/Efbfv/3/

$('#the_input_id').keyup(function() {
    updateTotal();
});

$('#the_input_id1').keyup(function() {
    updateTotal();
});

$('#the_input_id2').keyup(function() {
    updateTotal();
});

var updateTotal = function() {
    var input1 = parseInt($('#the_input_id').val());
    var input2 = parseInt($('#the_input_id1').val());
    var input3 = parseInt($('#the_input_id2').val());
    if (isNaN(input1) || isNaN(input2)) || isNaN(input3)) {
        $('#total').text('');
    } else {
        var max = 500;
        var total = input1 + (input2 * 2) + (input3 * 3);

        if (total > max) {
            $('#total').text('The maximum is ' + max);
            $('#total1').val(500);
        } else {
            $('#total').text(total);
            $('#total1').val(total);
        }


    }
};​

Upvotes: 0

Views: 715

Answers (1)

GregL
GregL

Reputation: 38151

You have an extra right parenthesis that is breaking it.

Change your if to:

if (isNaN(input1) || isNaN(input2) || isNaN(input3)) {
    $('#total').text('');
}

Upvotes: 9

Related Questions