Tuesday, December 1, 2015

Area of a Square in JavaScript

This sample program will solve for the area of a square using JavaScript as our programming language.

If you  have some questions please send me an email at jake.r.pomperada@gmail.com and jakerpomperada@yahoo.com

My mobile number here in the Philippines is 09173084360.


Program Listing
 
 <html>
     <head>
         <Title>Area of a Square in JavaScript</Title>
     </head>   
       
    <body>   
  <h1> Area of a Square in JavaScript </h1>
<br>     

    Base :
      <input type="text" id="Base"/>
         <BR>
     Height:          :
      <input type="text" id="Height"/>
         <BR>   
  
         &nbsp;&nbsp;
             <input
                   type="button"
                   id="btnArea"
                    onclick="Area();"
                    value = "Compute"/>
             <div id = "divresult"></div>
     </body>
            
      <script>
           function Area(){
               var Base = document.getElementById("Base");
              var Height = document.getElementById("Height");
               var basevalue = Base.value;
               var heightvalue = Height.value;
               var result = (basevalue*heightvalue)/2;
               var divresult=document.getElementById("divresult");
               divresult.innerHTML=result;
           }
     </script>
                         
    </html>

No comments:

Post a Comment