PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, September 17, 2022

[FIXED] How to use the if else conditional loop?

 September 17, 2022     if-statement, loops, printing, reactjs     No comments   

Issue

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

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 (&)



Answered By - A_Al3bad
Answer Checked By - Timothy Miller (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing