Link to home
Start Free TrialLog in
Avatar of Whing Dela Cruz
Whing Dela CruzFlag for Anguilla

asked on

Javascript the "if condition with Or"

Hi experts, I want to put  "Or" in the if condition which codes are something like this,

If (result = 0 or Nan) //Either of the two
{
  alert("Something wrong!")
}
ASKER CERTIFIED SOLUTION
Avatar of hielo
hielo
Flag of Wallis and Futuna image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Whing Dela Cruz

ASKER

Hi hielo, I changed "result===0" into "result==0" then now the code is working. However, I'm having trouble with the condition else, as the code shown below. even the "(( isNaN(result) || result==0 ))" both correct but the alert on else will appear. Is there any part of this code is wrong?

<script>
function CheckSalesTable()
        {
            var result = "0";
            var z = 1;
            var tbl = document.getElementById('SalesTable');
            var tdXFirstCell = tbl.querySelectorAll('tr td:nth-child(5)');  
            for(var [i =0; s < tdXFirstCell.length; [i++)
            {
              result = tdXFirstCell[[i].lastChild.value;
              if (( isNaN(result) || result==0 ))
              {
               alert("Your order number " + z + " is wrong in quantity");
              }
              else
              {
               alert("b88")
              }
              result = 0;
              z = (z + 1);
            }
        }
</script>
As instructed by the system, I added [] for all "i" in the codes.. Thank you
Hi hielo, Sorry for miss leading my question. The solution you have given to me is already correct, the only problem is my implementation of the codes. Thank you so much!
Thank you much!
If you can give me bonus about this question I need to put some "exit" here, after the alert. What I need is to stop the transaction if there something wrong on it. I tried to use break; but it doesn't work. Thank you!

if( isNaN(result) || result===0 )
{
    alert( "Something is wrong" );
}
>>          for(var [i =0; s < tdXFirstCell.length; [i++)
Get rid of the bracket to the left of both i variables.
 Your test condition on the loop uses an "s".  You probably meant to use an i.  It should be:
           for(var i =0; i < tdXFirstCell.length; i++)

>>               result = tdXFirstCell[[ i ].lastChild.value;
You have one left bracket too many to the left of the i.  It should be:
              result = tdXFirstCell[ i ].lastChild.value;

Open in new window

Just type
return;

after the alert.
Thank you hielo, everything is noted! Thanks for your for help it helps me a lot pursuing my project.