Create a Calculator in HTML - CSS - JAVA Script

How to Create a Calculator Website Based HTML, CSS with JAVAScript

 HTML File (index.html):

<!DOCTYPE html>
<html>
  <head>
    <title>Calculator</title>
    <link rel="stylesheet" type="text/css" href="style.css">
  </head>
  <body>
    <div class="calculator">
      <div class="screen">
        <input type="text" id="result" disabled>
      </div>
      <div class="keys">
        <button class="operator" onclick="clearResult()">C</button>
        <button class="operator" onclick="backspace()">&lt;</button>
        <button class="operator" onclick="getResult('%')">%</button>
        <button class="operator" onclick="getResult('/')">/</button>
        <button onclick="getResult('7')">7</button>
        <button onclick="getResult('8')">8</button>
        <button onclick="getResult('9')">9</button>
        <button class="operator" onclick="getResult('*')">*</button>
        <button onclick="getResult('4')">4</button>
        <button onclick="getResult('5')">5</button>
        <button onclick="getResult('6')">6</button>
        <button class="operator" onclick="getResult('-')">-</button>
        <button onclick="getResult('1')">1</button>
        <button onclick="getResult('2')">2</button>
        <button onclick="getResult('3')">3</button>
        <button class="operator" onclick="getResult('+')">+</button>
        <button class="operator" onclick="getResult('+-')">+/-</button>
        <button onclick="getResult('0')">0</button>
        <button onclick="getResult('.')">.</button>
        <button class="operator" onclick="calculate()">=</button>
      </div>
    </div>
    <script src="script.js"></script>
  </body>
</html>


CSS File (style.css):

.calculator {
  width: 300px;
  margin: 50px auto;
  border: 2px solid #ccc;
  border-radius: 5px;
  background-color: #f4f4f4;
  box-shadow: 5px 5px 5px #ccc;
  font-family: Arial, sans-serif;
}

.screen {
  width: 100%;
  height: 60px;
  padding: 5px;
  background-color: #fff;
  text-align: right;
  box-shadow: inset 0 0 5px #ccc;
}

#result {
  width: 95%;
  height: 50px;
  font-size: 28px;
  border: none;
  outline: none;
  text-align: right;
}

.keys {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-gap: 5px;
  padding: 5px;
}

button {
  width: 100%;
  height: 50px;
  font-size: 22px;
  background-color: #ccc;
  border: none;
  border-radius: 5px;
  cursor: pointer;
}

.operator {
  background-color: #ff6600;
  color: #fff;
}


JavaScript File (script.js):

let result = document.getElementById("result");

function getResult(value) {
  result.value += value;
}

function clearResult() {
  result.value = "";
}

function backspace() {
  result.value = result.value.slice(0, -1);
}

function calculate



Comments