0

i have this if else statement that always return ( other than 0 ) 'hey', but when the condition == 0, it will not display the 'ho' value. Appreciate advice. Thanks.

$('#icNumber').on('change', function(){
    let num = $(this).val().substr(13,1) %2
    
    if(num){
        $('#tortrix')
        .removeClass('d-none')
        .addClass('d-block form-control animated fadeIn')
        .attr('value', function(i, oriVal){
            if(num == 0) {
                console.log('ho')
                return 'value','Testatrix';
            } else {
                console.log('hey')
                return 'value','Testator';

            }
        })
    }
        else if (num == "") {
        $('#tortrix').removeClass('d-block').addClass('d-none')
    }
})
Joe_T
  • 15
  • 4
  • Use `===`! Don't use `==` – 0stone0 Oct 14 '20 at 15:17
  • I wouldn't immediately call this a duplicate--it's a misunderstanding of string vs. number. `.val() returns a string, not a number. Therefore calling `if (num == 0)` always returns false, since num is a string, not a number. You should put 0 in quotations to match a string: `if (num == "0")`. However, using `===` will of course ignore this difference in object type. – Hello World Oct 14 '20 at 21:03

0 Answers0