I need some help in this conditional code.
In order to store the required data to the variable paw
, I have three conditions.
- If
nameu
is not blank or empty andempidu
is blank or empty, it should store theTitle : nameu
only. - Else if
nameu
is blank or empty andempidu
is not blank or empty, it should store theEmpID : empidu
only. - 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
I think I am either writing wrong statements or logic. Please help me.
CodePudding user response:
You should use logical AND operator (&&) to evaluate multiple expressions instead of bitwise AND (&)