Site Title

๐Ÿ–ฅ๏ธ The Coders (group name)

๐Ÿงฎ Calculator Project Blog

๐Ÿ‘ฉโ€๐Ÿ’ป The Coders

Name GitHub Profile
Precia Verma github.com/precia-verma
Krystal github.com/krystal-727
Tasha (Struti) github.com/StutiPandey19

๐Ÿ“ Hack 1: Notebook

calculator.md


๐Ÿš€ Hack 2: Your Own Feature

Feature Name: JS Calculator

Purpose:
The JS Calculator is an interactive web-based calculator built with HTML, CSS, and JavaScript. Its purpose is to help users perform basic arithmetic operations (addition, subtraction, multiplication, division) directly in the browser. The calculator features a visually appealing, right-justified display, responsive buttons for numbers and operations, and supports decimal calculations. It also includes a clear (A/C) button to reset the calculation and an equals button to compute results, making it a practical tool for learning and practicing JavaScript DOM manipulation and event handling.

Feature Name: Right-Justified Output Display

Purpose:
This feature ensures that the calculatorโ€™s result/output is always aligned to the right side of the display area, mimicking the behavior of real-world calculators. It improves readability, especially for large or decimal numbers, and provides a familiar user experience. This makes it easy for users to read and interpret results as they perform calculations.

Example CSS:

display: flex;
align-items: center;
justify-content: flex-end; /* right-align text */

This makes numbers and results easy to read, especially for long or decimal values.

Feature Name: Clear (A/C) Button

Purpose:
The calculator includes an โ€œA/Cโ€ (All Clear) button that resets the calculator to its initial state. When clicked, it sets the display back to 0 and clears any stored numbers or operations, allowing the user to start a new calculation.

Example JavaScript:

function clearCalc () {
	firstNumber = null;
	output.innerHTML = "0";
	nextReady = true;
}

The button is styled and placed in the calculator grid for easy access.


๐ŸŽฎ Try the Calculator

Link to Game: https://precia-verma.github.io/Group-projects/calculator


๐Ÿ–ผ๏ธ Picture of Code

Image

๐Ÿ› ๏ธ What We Changed and Why

These changes make the calculator more visually appealing, easier to use, and a better learning tool for exploring JavaScript and UI design!


๐Ÿ” How the Calculator Works: The calculate Function

Below is the main function that performs the math operations in our calculator:

function calculate (first, second) {
  let result = 0;
  switch (operator) {
    case "+":
      result = first + second;
      break;
    case "-":
      result = first - second;
      break;
    case "*":
      result = first * second;
      break;
    case "/":
      result = first / second;
      break;
    default:
      break;
  }
  return result;
}

What does this code mean and what does it do?

This function is called whenever you press an operation or the equals button, so itโ€™s the core of how the calculator computes answers!