+ 1
Please tell me the meaning of voteable = ( age < 18) ? , and what is the meaning of ? (question mark) here ????????
<!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>
6 odpowiedzi
+ 1
thanks buddy,
please,can u explain the meaning of ? (question mark) here.
+ 1
no problem , brother
0
The ?: is the ternary operator,
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Conditional_Operator
Before the ? goes the condition, if true then whatever is before the : is used, if false then whatever is after the : is used.
It is similar to an if else but this is a 1 liner... usually.
0
The ? is part of the ternary operator's syntax.
0
thanks , now i got it :)
brother can u suggest me a good website for javascript other than w3schools
0
I wish I could help you there but I don't program in javascript most of the time. So I don't know alot about it :(