+ 1

This is ternary operator.... Can anyone make this code by using if else statement (javascript)

<!DOCTYPE html> <html> <body> <p>Input your age and click the button:</p> <input id="age" value="18" /> <button onclick="myFunction()">Try it</button> <p id="demo"></p> <script> function myFunction() { var age, voteable; age = document.getElementById("age").value; voteable = (age < 18) ? "Too young":"Old enough"; document.getElementById("demo").innerHTML = voteable + " to vote."; } </script> </body> </html>

30th Nov 2017, 4:39 PM
Karan Rajput
Karan Rajput - avatar
1 ответ
+ 8
Write this in place of the line with ternary operator. if (age < 18) voteable = "Too young"; else voteable = "Old enough";
30th Nov 2017, 5:02 PM
Krishna Teja Yeluripati
Krishna Teja Yeluripati - avatar