ahmed0saber

Calculator 2 in HTML , CSS , JS

Nov 22nd, 2020
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <html>
  2. <head>
  3. <title>Calculator</title>
  4. <script>
  5. function dis(val)
  6. {document.getElementById("result").value+=val}
  7. function solve()
  8. {let x=document.getElementById("result").value
  9. let y=eval(x)
  10. document.getElementById("result").value=y}
  11. function clr()
  12. {document.getElementById("result").value=""}
  13. </script>
  14. <style>
  15. #d1{
  16. position:absolute;
  17. top:25%;
  18. left:25%;
  19. margin:auto;
  20. text-align:center;
  21. background-color:#9DCBEE;
  22. box-shadow: 10px 10px 5px #C8D8DF;}
  23. </style>
  24. </head>
  25. <body style="background:#DDEEFF">
  26. <div align="center" id="d1">
  27. <table>
  28. <tr>
  29. <td colspan="3"><input type="text" id="result" width="100%"/></td>
  30. </tr>
  31. <tr>
  32. <td><input type="button" onclick="clr()" value="C" style="width:100%"/></td>
  33. <td><input type="button" onclick="dis('+')" value="+" style="width:100%"/></td>
  34. <td><input type="button" onclick="solve()" value="=" style="width:100%"/></td>
  35. </tr>
  36. <tr>
  37. <td><input type="button" onclick="dis('-')" value="-" style="width:100%"/></td>
  38. <td><input type="button" onclick="dis('*')" value="*" style="width:100%"/></td>
  39. <td><input type="button" onclick="dis('/')" value="/" style="width:100%"/></td>
  40. </tr>
  41. <tr>
  42. <td><input type="button" onclick="dis('1')" value="1" style="width:100%"/></td>
  43. <td><input type="button" onclick="dis('2')" value="2" style="width:100%"/></td>
  44. <td><input type="button" onclick="dis('3')" value="3" style="width:100%"/></td>
  45. </tr>
  46. <tr>
  47. <td><input type="button" onclick="dis('4')" value="4" style="width:100%"/></td>
  48. <td><input type="button" onclick="dis('5')" value="5" style="width:100%"/></td>
  49. <td><input type="button" onclick="dis('6')" value="6" style="width:100%"/></td>
  50. </tr>
  51. <tr>
  52. <td><input type="button" onclick="dis('7')" value="7" style="width:100%"/></td>
  53. <td><input type="button" onclick="dis('8')" value="8" style="width:100%"/></td>
  54. <td><input type="button" onclick="dis('9')" value="9" style="width:100%"/></td>
  55. </tr>
  56. <tr>
  57. <td><br/></td>
  58. <td><input type="button" onclick="dis('0')" value="0" style="width:100%"/></td>
  59. <td><br/></td>
  60. </tr>
  61. </table>
  62. </div>
  63. </body>
Advertisement
Add Comment
Please, Sign In to add comment