-
Notifications
You must be signed in to change notification settings - Fork 400
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Reverse Polish Notation Calculator (#899)
- Loading branch information
Showing
5 changed files
with
183 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# <p align="center">RPN Calculator</p> | ||
|
||
## Description :- | ||
|
||
RPN(Reverse Polish Notation) Calculator represents expressions by placing the operator symbol after the operands. | ||
|
||
## Tech Stacks :- | ||
|
||
- HTML | ||
- CSS | ||
- JavaScript | ||
|
||
## Screenshots :- | ||
|
||
![image](https://github.com/Rakesh9100/CalcDiverse/assets/73993775/18f3c287-2e10-4b2a-a714-5f5faf03dc7b) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<link rel="stylesheet" href="style.css"> | ||
<title>RPN Calculator</title> | ||
</head> | ||
<body> | ||
<div class="container"> | ||
<h1>RPN Calculator</h1> | ||
<input type="text" id="expression" placeholder="Enter RPN expression"> | ||
<button onclick="calculateRPN()">Calculate</button> | ||
<div class="result" id="result"></div> | ||
</div> | ||
<script src="script.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
function evaluateRPN(expression) { | ||
const stack = []; | ||
const operators = { | ||
'+': (a, b) => a + b, | ||
'-': (a, b) => a - b, | ||
'*': (a, b) => a * b, | ||
'/': (a, b) => { | ||
if (b === 0) { | ||
throw new Error("Division by zero"); | ||
} | ||
return a / b; | ||
} | ||
}; | ||
|
||
expression.split(' ').forEach(token => { | ||
if (operators[token]) { | ||
const b = stack.pop(); | ||
const a = stack.pop(); | ||
if (a === undefined || b === undefined) { | ||
throw new Error("Invalid expression: insufficient operands"); | ||
} | ||
stack.push(operators[token](a, b)); | ||
} else { | ||
const number = parseFloat(token); | ||
if (isNaN(number)) { | ||
throw new Error(`Invalid token: ${token}`); | ||
} | ||
stack.push(number); | ||
} | ||
}); | ||
|
||
if (stack.length !== 1) { | ||
throw new Error("Invalid expression: too many operands"); | ||
} | ||
|
||
return stack.pop(); | ||
} | ||
|
||
function calculateRPN() { | ||
const expression = document.getElementById('expression').value; | ||
const resultDisplay = document.getElementById('result'); | ||
|
||
try { | ||
const result = evaluateRPN(expression); | ||
resultDisplay.textContent = `Result: ${result}`; | ||
} catch (e) { | ||
resultDisplay.textContent = `Error: ${e.message}`; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
body { | ||
font-family: Arial, sans-serif; | ||
background: #262626; /* Adjust background color for better contrast */ | ||
margin: 0; | ||
padding: 50px; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
height: 100vh; | ||
} | ||
|
||
.container { | ||
max-width: 500px; | ||
width: 100%; | ||
background: #00ffa0; /* Neo Brutalism background */ | ||
padding: 1rem; | ||
border-radius: 1rem; | ||
border: 0.5vmin solid #05060f; | ||
box-shadow: 0.4rem 0.4rem #05060f; | ||
overflow: hidden; | ||
color: black; | ||
text-align: center; | ||
} | ||
|
||
input, button { | ||
padding: 10px; | ||
margin: 5px 0; /* Adjust margin to vertical only */ | ||
font-size: 16px; | ||
width: calc(100% - 24px); /* Ensure input and button take full width minus padding */ | ||
box-sizing: border-box; /* Include padding in width calculation */ | ||
} | ||
|
||
button { | ||
background-color: #05060f; /* Button color adjustment */ | ||
color: #00ffa0; | ||
border: none; | ||
border-radius: 0.5rem; | ||
cursor: pointer; | ||
} | ||
|
||
button:hover { | ||
background-color: #000; /* Darker hover color */ | ||
} | ||
|
||
.result { | ||
margin-top: 20px; | ||
font-size: 20px; | ||
} | ||
|
||
/* Additional styles for card content */ | ||
.pricing-block-content { | ||
display: flex; | ||
flex-direction: column; | ||
gap: 0.5rem; | ||
} | ||
|
||
.pricing-plan { | ||
color: #05060f; | ||
font-size: 1.3rem; | ||
line-height: 1.25; | ||
font-weight: 700; | ||
} | ||
|
||
.price-value { | ||
display: flex; | ||
color: #05060f; | ||
font-size: 1.8rem; | ||
line-height: 1.25; | ||
font-weight: 700; | ||
} | ||
|
||
.pricing-note { | ||
opacity: 0.8; | ||
} | ||
|
||
.check-list { | ||
display: flex; | ||
flex-direction: column; | ||
gap: 0.5rem; | ||
margin-top: 0.5rem; | ||
} | ||
|
||
.check-list-item { | ||
display: flex; | ||
align-items: center; | ||
gap: 4px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters