diff --git a/Calculator/yash_pokharna/index.html b/Calculator/yash_pokharna/index.html new file mode 100644 index 000000000..897d7c425 --- /dev/null +++ b/Calculator/yash_pokharna/index.html @@ -0,0 +1,35 @@ + + + + + + Calculator + + + +
+ +
+ + + +
+ + + +
+ + + +
+ + + +
+ + +
+
+ + + diff --git a/Calculator/yash_pokharna/script.js b/Calculator/yash_pokharna/script.js new file mode 100644 index 000000000..a35f062c8 --- /dev/null +++ b/Calculator/yash_pokharna/script.js @@ -0,0 +1,38 @@ +let display = document.getElementById("display"); + +function clearDisplay() { + display.value = ""; +} + +function deleteLast() { + display.value = display.value.slice(0, -1); +} + +function appendNumber(number) { + if (number === '.' && display.value.includes('.') && !isNaN(display.value.slice(-1))) { + alert("Error: Multiple decimal points are not allowed."); + return; + } + display.value += number; +} + +function addOperator(operator) { + const lastChar = display.value.slice(-1); + if (!display.value || isNaN(lastChar)) { + alert("Error: Cannot add consecutive operators."); + return; + } + display.value += operator; +} + +function calculate() { + try { + if (display.value.includes("/0")) { + alert("Error: Division by zero is undefined."); + return; + } + display.value = eval(display.value); + } catch (error) { + alert("Error: Invalid operation."); + } +} diff --git a/Calculator/yash_pokharna/style.css b/Calculator/yash_pokharna/style.css new file mode 100644 index 000000000..ff47df328 --- /dev/null +++ b/Calculator/yash_pokharna/style.css @@ -0,0 +1,52 @@ +body { + font-family: Arial, sans-serif; + display: flex; + justify-content: center; + align-items: center; + height: 100vh; + margin: 0; + background-color: #f5f5f5; +} + +.calculator { + background: #fff; + padding: 20px; + border-radius: 10px; + box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2); +} + +#display { + width: 100%; + height: 50px; + font-size: 18px; + margin-bottom: 10px; + text-align: right; + padding: 5px; + border: 1px solid #ccc; + border-radius: 5px; + background: #f9f9f9; +} + +.buttons { + display: grid; + grid-template-columns: repeat(4, 1fr); + gap: 10px; +} + +button { + height: 50px; + font-size: 18px; + border: none; + border-radius: 5px; + cursor: pointer; + background: #007BFF; + color: white; +} + +button:hover { + background: #0056b3; +} + +button:active { + background: #003f7f; +}