𝗖𝗮𝗹𝗰𝘂𝗹𝗮𝘁𝗼𝗿 𝗣𝗿𝗼𝗷𝗲𝗰𝘁 𝗨𝘀𝗶𝗻𝗴 𝗛𝗧𝗠𝗟, 𝗖𝗦𝗦 & 𝗝𝗮𝘃𝗮𝗦𝗰𝗿𝗶𝗽𝘁!

Calculator Project Using HTML CSS & JavaScript

<!DOCTYPE html>

<html lang=”en”>

<head>

  <meta charset=”UTF-8″>

  <meta name=”viewport” content=”width=device-width, initial-scale=1.0″>

  <title>Simple Calculator</title>

  <link rel=”stylesheet” href=”styles.css”>

</head>

<body>

    <h1>Simple Calculator Project</h1>

    <h2 style= “font-size:15px;”>using HTML, CSS, Java Script</h2>

  <div class=”calculator”>

    <input type=”text” id=”display” readonly>

    <div class=”buttons”>

      <button onclick=”appendNumber(‘7’)”>7</button>

      <button onclick=”appendNumber(‘8’)”>8</button>

      <button onclick=”appendNumber(‘9’)”>9</button>

      <button class=”green”onclick=”appendOperator(‘+’)”>+</button>

      <button onclick=”appendNumber(‘4’)”>4</button>

      <button onclick=”appendNumber(‘5’)”>5</button>

      <button onclick=”appendNumber(‘6’)”>6</button>

      <button class=”green”onclick=”appendOperator(‘-‘)”>-</button>

      <button onclick=”appendNumber(‘1’)”>1</button>

      <button onclick=”appendNumber(‘2’)”>2</button>

      <button onclick=”appendNumber(‘3’)”>3</button>

      <button class=”green” onclick=”appendOperator(‘*’)”>*</button>

        <button class=”red” onclick=”clearDisplay()”>C</button>

       <button class=”green” onclick=”appendNumber(‘0’)”>0</button>

      <button class=”green” onclick=”appendOperator(‘/’)”>/</button>

      <button class=”green” onclick=”calculate()”>=</button>

    </div>

  </div>

  <script src=”script.js”></script>

</body>

</html>

h1,h2 {  

            text-align: center;

            color: #333; /* Color for the title */

        }

.calculator {

  width: 200px;

  margin: 10px auto;

}

#display {

  width: 95%;

  margin-bottom: 10px;

  font-size: 20px;

  padding: 5px;

  background: linear-gradient(to right, #0DB1D5, #8FF235); /* Gradient from green to blue */

  border: 1px solid #000;

  border-radius: 5px;

}

.buttons {

  display: grid;

  grid-template-columns: repeat(4, 1fr);

  gap: 5px;

}

button {

  padding: 10px;

  font-size: 20px;

  background: linear-gradient(to right, #0DB1D5, #8FF235); /* Gradient from green to blue */

  border: none;

  color: white;

  text-align: center;

  text-decoration: none;

  display: inline-block;

  margin: 4px 2px;

  cursor: pointer;

  border-radius: 5px;

}

button:hover {

  filter: brightness(90%);

}

let display = document.getElementById(‘display’);

let currentValue = ”;

function appendNumber(number) {

  currentValue += number;

  display.value = currentValue;

}

function appendOperator(operator) {

  currentValue += operator;

  display.value = currentValue;

}

function clearDisplay() {

  currentValue = ”;

  display.value = ”;

}

function calculate() {

  try {

    currentValue = eval(currentValue);

    display.value = currentValue;

  } catch (error) {

    display.value = ‘Error’;

  }

}

Leave a Reply

Your email address will not be published. Required fields are marked *