Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Prompt Box Calculator #618

Closed
wants to merge 11 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions Calculators/Prompt Box Calculator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Simple Calculator using JavaScript Operations

This is a basic calculator application built using JavaScript. It performs standard arithmetic operations such as addition, subtraction, multiplication, and division.

![ouput](./calc_output.PNG)

## Features

- Addition
- Subtraction
- Multiplication
- Division

## How It Works

- The calculator logic is implemented using JavaScript.
- Each button click triggers a corresponding function that updates the display with the result of the operation.
- The `eval()` function is used to evaluate the mathematical expression entered by the user.
24 changes: 24 additions & 0 deletions Calculators/Prompt Box Calculator/calc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
let op = prompt("Enter operation (+, -, *, /)");

if (op != "+" && op != "-" && op != "/" && op != "*") {
document.write("Invalid operation (please try again!)");
} else {
let firstNumber = prompt("Enter first number");
let secondNumber = prompt("Enter second number");

if (op == "+") {
document.write(+firstNumber + +secondNumber);
} else if (op == "-") {
document.write(+firstNumber - +secondNumber);
} else if (op == "*") {
document.write(+firstNumber * +secondNumber);
} else if (op == "/") {
document.write(+firstNumber / +secondNumber);
}
}






Binary file added Calculators/Prompt Box Calculator/calc_output.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions Calculators/Prompt Box Calculator/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<html>
<head>
<script src="calc.js"></script>
</head>
<body></body>
</html>
Loading