Skip to content

Collins096/Build-A-Calculator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

1 Commit
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿงฎ JavaScript Math Functions

This project contains simple JavaScript functions that perform basic mathematical operations. It is useful for beginners learning how to write and use functions in JavaScript.


๐Ÿ“Œ Features

The program includes the following functions:

  • โž• Addition โ€“ Adds two numbers
  • โž– Subtraction โ€“ Finds the difference between two numbers
  • โœ–๏ธ Multiplication โ€“ Multiplies two numbers
  • โž— Division โ€“ Divides two numbers (handles division by zero)
  • ๐Ÿ”ฒ Square โ€“ Calculates the square of a number
  • โˆš Square Root โ€“ Finds the square root of a number

๐Ÿ“‚ Code Overview

1. Addition

function calculateSum(num1, num2) {
  return num1 + num2;
}

2. Subtraction
function calculateDifference(num1, num2) {
  return num1 - num2;
  

3. Multiplication
function calculateProduct(num1, num2) {
  return num1 * num2;
}
4. Division (with error handling)
function calculateQuotient(num1, num2) {
  return num2 === 0 ? "Error: Division by zero" : num1 / num2;
}
5. Square
function calculateSquare(num) {
  return num ** 2;
}
6. Square Root
function calculateSquareRoot(num) {
  return Math.sqrt(num);
}



โ–ถ๏ธ Example Output


7
20
10
17
11
8
65
0.6363636363636364
Error: Division by zero
4
81



๐Ÿš€ How to Run
Copy the code into a file named mathFunctions.js

Run using Node.js:

node mathFunctions.js


๐ŸŽฏ Purpose
This project helps you understand:

Function creation in JavaScript

Parameters and return values

Basic arithmetic operations

Simple error handling



๐Ÿ› ๏ธ Future Improvements
Add more advanced math functions (e.g., power, logarithms)

Create a user input interface
Convert into a calculator app

About

A simple JavaScript utility project demonstrating core programming concepts through custom math functions such as addition, subtraction, multiplication, division, square, and square root.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors