If-1

 

JavaScript if condition is used to execute a statement if the condition is true, In our example, if the age is less than 18 then "You are not qualified for Voting" message will be displayed else "You are qualified for Voting" message will be displayed. See the code snippet for JavaScript If condition:

 
 
 
<!DOCTYPE html> <html> <head> <title>Welcome to LearnKode - A code learning platform</title> </head> <body> <button onclick="dayGreeting()">Show the message</button> <p id="sample"></p> <script> function dayGreeting() { var age = 19 var message; if (age < 18) { message = "You are not qualified for Voting"; } else { message = "You are qualified for Voting"; } document.getElementById("sample").innerHTML = message; } </script> </body> </html>
Output