JavaScript Practice Questions And Answer

Problem: Write a program to check a person is eligible for voting or not,by creating object.
Solution:
            <html>
              <head>
               <script>
                function demo1()
                {
                  //objects in Javascript
                  var person1 = 
                  {
                    name : "Amit",
                    age : 23,
                    gender : "Male"
                  }
                    document.write("<br>"+ person1.name)
                    document.write("<br>"+ person1.age)
                    document.write("<br>"+ person1.gender)
                     person1.age = 8
                     document.write("<br>"+ person1.age)
                       //check if person1 can vote or not
                        if(person1.age >= 18)
                        {
                          document.write("<br> eligible for voting")
                        }
                        else
                        {
                          document.write("<br> can not vote")
                        }
                    }
               </script>
            </head>
            <body>
                <input type="button" value="Go" onclick="demo1()"/><br>
            </body>
        </html>
          

Contact Us

Our Address

Office no.- 401,Shekhar Central Building ,Palasiya, Pin-code:452001, Indore

Email Us

contact@codebetter.in

Call Us

+91 88230 75444, +91 99939 28766

Loading
Your message has been sent. Thank you!