Compare commits
No commits in common. "ssmp/tsc-10-r2" and "main" have entirely different histories.
ssmp/tsc-1
...
main
@ -8,7 +8,6 @@ Greenfield project. Implementation is driven by the Vexa AI-SDLC pipeline (Jira
|
|||||||
/
|
/
|
||||||
├── index.html # Calculator UI (semantic HTML5)
|
├── index.html # Calculator UI (semantic HTML5)
|
||||||
├── styles.css # Responsive CSS layout and styling
|
├── styles.css # Responsive CSS layout and styling
|
||||||
├── calculator.js # Calculation engine + UI wiring (plain JS, no build step)
|
|
||||||
├── README.md # Project overview
|
├── README.md # Project overview
|
||||||
└── CLAUDE.md # This file
|
└── CLAUDE.md # This file
|
||||||
```
|
```
|
||||||
@ -30,7 +29,6 @@ No dev server or REPL is configured yet. Update this section once the implementa
|
|||||||
- **Domain**: Simple Calculator — arithmetic operations (add, subtract, multiply, divide at minimum).
|
- **Domain**: Simple Calculator — arithmetic operations (add, subtract, multiply, divide at minimum).
|
||||||
- **Stack**: Plain HTML/CSS/JS — no framework or build step.
|
- **Stack**: Plain HTML/CSS/JS — no framework or build step.
|
||||||
- `index.html` contains the full UI structure: operand inputs, operation buttons, calculate/clear buttons, result `<output>`, and an error `<p role="alert">`.
|
- `index.html` contains the full UI structure: operand inputs, operation buttons, calculate/clear buttons, result `<output>`, and an error `<p role="alert">`.
|
||||||
- `calculator.js` exposes a `calculate(a, b, operation)` function returning `{ result }` or `{ error }`, and an IIFE that wires the engine to the DOM.
|
|
||||||
|
|
||||||
## Code Style
|
## Code Style
|
||||||
|
|
||||||
|
|||||||
@ -1,62 +0,0 @@
|
|||||||
function calculate(a, b, operation) {
|
|
||||||
switch (operation) {
|
|
||||||
case 'add': return { result: a + b };
|
|
||||||
case 'subtract': return { result: a - b };
|
|
||||||
case 'multiply': return { result: a * b };
|
|
||||||
case 'divide':
|
|
||||||
if (b === 0) return { error: 'Division by zero is not allowed.' };
|
|
||||||
return { result: a / b };
|
|
||||||
default:
|
|
||||||
return { error: 'Unknown operation: ' + operation };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
(function () {
|
|
||||||
var form = document.getElementById('calculator-form');
|
|
||||||
var operationBtns = document.querySelectorAll('button[name="operation"]');
|
|
||||||
var resultEl = document.getElementById('result');
|
|
||||||
var errorEl = document.getElementById('error-message');
|
|
||||||
var selectedOperation = null;
|
|
||||||
|
|
||||||
operationBtns.forEach(function (btn) {
|
|
||||||
btn.addEventListener('click', function () {
|
|
||||||
operationBtns.forEach(function (b) { b.setAttribute('aria-pressed', 'false'); });
|
|
||||||
btn.setAttribute('aria-pressed', 'true');
|
|
||||||
selectedOperation = btn.value;
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
form.addEventListener('submit', function (e) {
|
|
||||||
e.preventDefault();
|
|
||||||
resultEl.textContent = '';
|
|
||||||
errorEl.textContent = '';
|
|
||||||
|
|
||||||
var a = parseFloat(document.getElementById('operand1').value);
|
|
||||||
var b = parseFloat(document.getElementById('operand2').value);
|
|
||||||
|
|
||||||
if (isNaN(a) || isNaN(b)) {
|
|
||||||
errorEl.textContent = 'Please enter valid numbers for both operands.';
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!selectedOperation) {
|
|
||||||
errorEl.textContent = 'Please select an operation.';
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var outcome = calculate(a, b, selectedOperation);
|
|
||||||
|
|
||||||
if (outcome.error) {
|
|
||||||
errorEl.textContent = outcome.error;
|
|
||||||
} else {
|
|
||||||
resultEl.textContent = outcome.result;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
form.addEventListener('reset', function () {
|
|
||||||
resultEl.textContent = '';
|
|
||||||
errorEl.textContent = '';
|
|
||||||
operationBtns.forEach(function (btn) { btn.setAttribute('aria-pressed', 'false'); });
|
|
||||||
selectedOperation = null;
|
|
||||||
});
|
|
||||||
}());
|
|
||||||
@ -51,6 +51,5 @@
|
|||||||
<p id="error-message" role="alert" aria-label="Error message"></p>
|
<p id="error-message" role="alert" aria-label="Error message"></p>
|
||||||
</section>
|
</section>
|
||||||
</main>
|
</main>
|
||||||
<script src="calculator.js"></script>
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user