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
         function check(){
             var nbr;
             nbr = Number(document.getElementById("age").value);
             if(nbr < 18)
                alert("You are not an adult");
                alert("You are an adult");
      Enter your age: <input id="age">
      <button onclick="check()">Check</button>
Enter your age:
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 *