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

Plot No. 64, PU-4, Scheme 54, Behind C21 Mall near Hotel Holiday , AB Road, Indore Pin-code:452001

Email Us

contact@codebetter.in

Call Us

+91 88230 75444, +91 99939 28766

Loading
Your message has been sent. Thank you!