Advertisement
Hanafi112

kalkulator

Jun 29th, 2023
1,040
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 2.50 KB | Source Code | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4.     <title>Kalkulator</title>
  5.     <style>
  6.         .calculator {
  7.             width: 250px;
  8.             margin: 0 auto;
  9.             padding: 40px;
  10.             border: 1px solid #ccc;
  11.             border-radius: 4px;
  12.             display: grid;
  13.             grid-template-columns: repeat(3, 1fr);
  14.             grid-gap: 10px;
  15.         }
  16.         .calculator input[type="text"] {
  17.             grid-column: 1 / span 3;
  18.             width: 100%;
  19.             margin-bottom: 10px;
  20.             padding: 10px;
  21.             font-size: 18px;
  22.             border: 1px solid #ccc;
  23.             border-radius: 4px;
  24.         }
  25.         .calculator input[type="button"] {
  26.             width: 100%;
  27.             padding: 10px;
  28.             font-size: 18px;
  29.             border-radius: 4px;
  30.             cursor: pointer;
  31.         }
  32.     </style>
  33. </head>
  34. <body>
  35.     <div class="calculator">
  36.         <input type="text" id="result" readonly>
  37.         <input type="button" value="1" onclick="appendToResult('1')">
  38.         <input type="button" value="2" onclick="appendToResult('2')">
  39.         <input type="button" value="3" onclick="appendToResult('3')">
  40.         <input type="button" value="4" onclick="appendToResult('4')">
  41.         <input type="button" value="5" onclick="appendToResult('5')">
  42.         <input type="button" value="6" onclick="appendToResult('6')">
  43.         <input type="button" value="7" onclick="appendToResult('7')">
  44.         <input type="button" value="8" onclick="appendToResult('8')">
  45.         <input type="button" value="9" onclick="appendToResult('9')">
  46.         <input type="button" value="0" onclick="appendToResult('0')">
  47.         <input type="button" value="C" onclick="clearResult()">
  48.         <input type="button" value="+" onclick="appendToResult('+')">
  49.         <input type="button" value="-" onclick="appendToResult('-')">
  50.         <input type="button" value="*" onclick="appendToResult('*')">
  51.         <input type="button" value="=" onclick="calculateResult()">
  52.         <input type="button" value="/" onclick="appendToResult('/')">
  53.     </div>
  54.  
  55.     <script>
  56.         function appendToResult(value) {
  57.             document.getElementById('result').value += value;
  58.         }
  59.  
  60.         function clearResult() {
  61.             document.getElementById('result').value = '';
  62.         }
  63.  
  64.         function calculateResult() {
  65.             var result = eval(document.getElementById('result').value);
  66.             document.getElementById('result').value = result;
  67.         }
  68.     </script>
  69. </body>
  70. </html>
  71.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement