JavaScript

Code to check if age is not less than 18 years in Javascript

In this tutorial, we are going to see a simple program in JavaScript to check the age of a person, if the age is greater than 18 years, display the message “You are an adult” otherwise display “You are not an adult “.
 

Program to verify a person’s age
<html>
   <head>
      <script>
         function check(){
             var nbr;
             nbr = Number(document.getElementById("age").value);
             if(nbr < 18)
             {
                alert("You are not an adult");
             }
             else
             {
                alert("You are an adult");
             }
         }
      </script>
   </head>
   <body>
      Enter your age: <input id="age">
      <button onclick="check()">Check</button>
   </body>
</html>
Result
Enter your age:
[st_adsense] mcqMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More

Leave a Reply

Your email address will not be published. Required fields are marked *