Advertisement
goldnera

According To My Calculations Calculator

May 18th, 2023
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 2.50 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4.   <title>Calculator By Goldnera</title>
  5.   <link rel="stylesheet" type="text/css" href="style.css">
  6. </head>
  7. <body>
  8.   <div class="calculator">
  9.     <input type="text" id="result" readonly>
  10.     <div class="keypad">
  11.       <button onclick="clearResult()">C</button>
  12.       <button onclick="appendToResult('/')">/</button>
  13.       <button onclick="appendToResult('7')">7</button>
  14.       <button onclick="appendToResult('8')">8</button>
  15.       <button onclick="appendToResult('9')">9</button>
  16.       <button onclick="appendToResult('*')">*</button>
  17.       <button onclick="appendToResult('4')">4</button>
  18.       <button onclick="appendToResult('5')">5</button>
  19.       <button onclick="appendToResult('6')">6</button>
  20.       <button onclick="appendToResult('-')">-</button>
  21.       <button onclick="appendToResult('1')">1</button>
  22.       <button onclick="appendToResult('2')">2</button>
  23.       <button onclick="appendToResult('3')">3</button>
  24.       <button onclick="appendToResult('+')">+</button>
  25.       <button onclick="appendToResult('0')">0</button>
  26.       <button onclick="calculateResult()">=</button>
  27.     </div>
  28.   </div>
  29.  
  30.   <script src="script.js"></script>
  31. </body>
  32. </html>
  33. <style>.calculator {
  34.     width: 300px;
  35.     margin: 0 auto;
  36.     background-color: #f2f2f2;
  37.     border-radius: 8px;
  38.     box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.1);
  39.     padding: 20px;
  40.   }
  41.  
  42.   input {
  43.     width: 100%;
  44.     height: 50px;
  45.     font-size: 24px;
  46.     padding: 10px;
  47.     border: none;
  48.     border-radius: 4px;
  49.     margin-bottom: 20px;
  50.   }
  51.  
  52.   .keypad {
  53.     display: grid;
  54.     grid-template-columns: repeat(4, 1fr);
  55.     grid-gap: 10px;
  56.   }
  57.  
  58.   button {
  59.     width: 100%;
  60.     height: 60px;
  61.     font-size: 24px;
  62.     border: none;
  63.     border-radius: 4px;
  64.     background-color: #e0e0e0;
  65.     color: #333333;
  66.     cursor: pointer;
  67.     transition: background-color 0.3s ease;
  68.   }
  69.  
  70.   button:hover {
  71.     background-color: #cccccc;
  72.   }
  73.  
  74.   .clear {
  75.     grid-column: 1 / span 2;
  76.   }
  77.  
  78.   .zero {
  79.     grid-column: 1 / span 2;
  80.   }
  81.  
  82.   </style>
  83.   <script>function clearResult() { // To Open his file, save it and open it
  84.     document.getElementById("result").value = "";
  85.   }
  86.  
  87.   function appendToResult(value) {
  88.     document.getElementById("result").value += value;
  89.   }
  90.  
  91.   function calculateResult() {
  92.     var result = document.getElementById("result").value;
  93.     var calculatedResult = eval(result);
  94.     document.getElementById("result").value = calculatedResult;
  95.   }
  96.   </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement