Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to use the if else conditional loop?

I need some help in this conditional code.
In order to store the required data to the variable paw, I have three conditions.

  1. If nameu is not blank or empty and empidu is blank or empty, it should store the Title : nameu only.
  2. Else if nameu is blank or empty and empidu is not blank or empty, it should store the EmpID : empidu only.
  3. Else store both.

I have written the code myself, but it is not working. Here is the code :

var paw = "";
    if(nameu !== " ") {
       paw = JSON.stringify({
        Title: nameu
      });
    }
    else if(nameu === "" & empidu !== " ") {
       paw = JSON.stringify({
        EmpID: empidu
      });
    }
    else {
     paw = JSON.stringify({
      Title: nameu,
      EmpID: empidu,
    });
  }

Note : nameu (String) and empidu (number) are user input values

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I think I am either writing wrong statements or logic. Please help me.

>Solution :

You should use logical AND operator (&&) to evaluate multiple expressions instead of bitwise AND (&)

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading