Conditional(Ternary) Operator | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Conditional(Ternary) Operator

I just wanted to know one thing that is, if we are creating a login page from JavaScript and as the example shows, if the age is <18 it gives error else it proceeds forward with the login. Is that right?

2nd Jul 2018, 4:41 PM
Genesis
2 Answers
+ 12
var validateAge=prompt ('enter age') < 18 ? false : true; if(validateAge==true){ //validation code } else{ throw ("not allowed below18"); }
2nd Jul 2018, 5:18 PM
Prashanth Kumar
Prashanth Kumar - avatar
+ 18
Where is the example?
2nd Jul 2018, 4:43 PM
Igor Makarsky
Igor Makarsky - avatar