Condition | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 4

Condition

Is this possible to make a condition into another condition ?

3rd Jul 2018, 9:05 AM
Mr. Plopomi
Mr. Plopomi - avatar
5 Answers
+ 3
conditions just return true or false or 1 or 0 for a computational true or false. so anything that uses that return can have a condition in it. So like function test { return true; } let result = 9 > 3 && test() && !false && 1; is all valid and gives the result of 1 or true. You can use && for and meaning both sides have to result in true and || for or which means AT LEAST one side has to be true for the whole thing to return true. ! is used for not which returns the opposite of the result too. You can do conditions with many parts in for loops, if statements, turnery ifs, print statements, and many more.
4th Jul 2018, 9:21 AM
nk361
nk361 - avatar
+ 8
If you're referring to nested if-else statements, yes. It's possible have a conditional inside another conditional. You can also do it with ternary operators.
3rd Jul 2018, 9:10 AM
Jonathan Pizarra (JS Challenger)
Jonathan Pizarra (JS Challenger) - avatar
+ 5
Do you mean have a condition and within that condition is another condition Or do you mean change the condition
3rd Jul 2018, 9:11 AM
Agent
Agent - avatar
+ 4
Agent i mean something like this : var example = confirm("test1") if (example == true) { var exampleTwo = confirm("test2"); if (exampleTwo == false) { alert("test3"); } else { alert("test4"); } else { alert("test5"); }
3rd Jul 2018, 9:37 AM
Mr. Plopomi
Mr. Plopomi - avatar
+ 1
okay, thank you =D
3rd Jul 2018, 9:11 AM
Mr. Plopomi
Mr. Plopomi - avatar