How does it work | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
18th Oct 2022, 1:21 PM
DESMOND YEBOAH
DESMOND YEBOAH - avatar
2 Answers
0
Logical or : a || b => if any ond of a, b is true then total expression results true. If a is true then b won't be tested. If a is false then b going to be tested. Logical and : a && b => if both a, b are true then total expression results true. If a is false then b won't be tested. If a is true then only b going to be tested. Ternary opearator: (condition) ? Block1 : Block2 ; If condition is true then it evalutes Block1, otherwise Block2 evaluated. a, b are two conditional expressions.. hope it helps to clear.
18th Oct 2022, 4:37 PM
Jayakrishna 🇮🇳
0
user is first prompted to enter his/her first name which is stored in the firstName variable. user is further asked to enter his/her last name which is again stored in the lastName variable. if user input a value in the first name and last name prompt, then the value of firstName and lastName becomes true and since the OR operator selects the first truthy value, it assigns isNotFilled variable with true. The code again checks if isNotFilled is true. if it is indeed true, then the user is alerted to enter his/her details. In the case a user refuse to enter both first name and last name, firstName and lastName becomes false so the third operand of the OR operator is executed and since alert() returns undefined, the || operator move to the fourth operand which is true and return the value to isNot Filled. And if evalued and is true, follows the same pattern. In the case first name is filled and last name is not, isNotFilled is assigned true and user is asked to fill in his/her last name. In the case, user fill both firstName and lastName and isNotFilled is the same value as firstName and lastName is not empty, the user is shown a welcome message with his/her firstName and lastName.
18th Oct 2022, 5:29 PM
DESMOND YEBOAH
DESMOND YEBOAH - avatar