+ 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 odpowiedzi
+ 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