Recent-Post

header ads

Working Calculator

 
Calculator Html

<html> 

   <head> 

      <script> 

         //function that display value 

         function dis(val) 

         { 

             document.getElementById("result").value+=val 

         } 

           

         //function that evaluates the digit and return result 

         function solve() 

         { 

             let x = document.getElementById("result").value 

             let y = eval(x) 

             document.getElementById("result").value = y 

         } 

           

         //function that clear the display 

         function clr() 

         { 

             document.getElementById("result").value = "" 

         } 

      </script> 

      

   </head> 

   <!-- create table -->

   <body>

   <center>

      <div class = title >This Calculater Made By Priyanshu Kumar</div> 

      <table border="1"> 

         <tr> 

         </center>

            <td colspan="3"><input type="text" id="result"/></td> 

            <!-- clr() function will call clr to clear all value -->

            <td><input type="button" value="c" onclick="clr()"/> </td> 

         </tr> 

         <tr> 

            <!-- create button and assign value to each button -->

            <!-- dis("1") will call function dis to display value -->

            <td><input type="button" value="1" onclick="dis('1')"/> </td> 

            <td><input type="button" value="2" onclick="dis('2')"/> </td> 

            <td><input type="button" value="3" onclick="dis('3')"/> </td> 

            <td><input type="button" value="/" onclick="dis('/')"/> </td> 

         </tr> 

         <tr> 

            <td><input type="button" value="4" onclick="dis('4')"/> </td> 

            <td><input type="button" value="5" onclick="dis('5')"/> </td> 

            <td><input type="button" value="6" onclick="dis('6')"/> </td> 

            <td><input type="button" value="-" onclick="dis('-')"/> </td> 

         </tr> 

         <tr> 

            <td><input type="button" value="7" onclick="dis('7')"/> </td> 

            <td><input type="button" value="8" onclick="dis('8')"/> </td> 

            <td><input type="button" value="9" onclick="dis('9')"/> </td> 

            <td><input type="button" value="+" onclick="dis('+')"/> </td> 

         </tr> 

         <tr> 

            <td><input type="button" value="." onclick="dis('.')"/> </td> 

            <td><input type="button" value="0" onclick="dis('0')"/> </td> 

            <!-- solve function call function solve to evaluate value -->

            <td><input type="button" value="=" onclick="solve()"/> </td> 

            <td><input type="button" value="*" onclick="dis('*')"/> </td> 

         </tr> 

      </table>

      <!-- for styling -->

     

<style>

.title{

border-radius: 100px;

margin-bottom: 10px;

text-align:center;

width: 300px;

color:#ff4456;

border: solid black 1px;

}


input[type="button"]

{

border-radius: 30px;

background-color:#ff4456;

color: black;

border-color:#ff4456 ;

width:100px;

}

input[type="text"]

{

border-radius: 300px;

text-align: right;

background-color:white;

border-color: black ;

width:300px

}

</style>

   </body> 

</html>    




(OUTPUT)


Post a Comment

0 Comments