diff --git a/Calculator/Pratik1968/index.html b/Calculator/Pratik1968/index.html index 5f4df68aa..84edf2fe6 100644 --- a/Calculator/Pratik1968/index.html +++ b/Calculator/Pratik1968/index.html @@ -17,7 +17,9 @@ power:"7", clear:"8", backspace:"9", - decimal:"." + decimal:".", + sqrt:"10", + negate:"11" } @@ -30,6 +32,7 @@
+ @@ -45,6 +48,7 @@ + +
diff --git a/Calculator/bhpranit08/script.js b/Calculator/bhpranit08/script.js index aaa951975..be4cfd354 100644 --- a/Calculator/bhpranit08/script.js +++ b/Calculator/bhpranit08/script.js @@ -58,4 +58,27 @@ const equal = () => { realInput.value = "Error" inputEl.value = "Error" } +} + +const squareRoot = () => { + const inputEl = document.getElementById("input-el") + const realInput = document.getElementById("real-input-el") + + const currentValue = realInput.value + + if (currentValue === "" || currentValue === "Error") { + return + } + + const number = parseFloat(currentValue) + + if (number < 0) { + inputEl.value = "请输入非负数" + realInput.value = "" + return + } + + const result = Math.sqrt(number) + realInput.value = result.toString() + inputEl.value = result.toString() } \ No newline at end of file diff --git a/Calculator/yash_pokharna/index.html b/Calculator/yash_pokharna/index.html index 897d7c425..3a33a3511 100644 --- a/Calculator/yash_pokharna/index.html +++ b/Calculator/yash_pokharna/index.html @@ -13,7 +13,8 @@ -
+ +
diff --git a/Calculator/yash_pokharna/script.js b/Calculator/yash_pokharna/script.js index a35f062c8..f0cad4e8c 100644 --- a/Calculator/yash_pokharna/script.js +++ b/Calculator/yash_pokharna/script.js @@ -36,3 +36,19 @@ function calculate() { alert("Error: Invalid operation."); } } + +function calculateSqrt() { + const value = parseFloat(display.value); + + if (isNaN(value)) { + alert("Error: 请输入有效数字"); + return; + } + + if (value < 0) { + display.value = "请输入非负数"; + return; + } + + display.value = Math.sqrt(value); +} \ No newline at end of file diff --git a/Calculator/yash_pokharna/style.css b/Calculator/yash_pokharna/style.css index ff47df328..408715b86 100644 --- a/Calculator/yash_pokharna/style.css +++ b/Calculator/yash_pokharna/style.css @@ -29,7 +29,7 @@ body { .buttons { display: grid; - grid-template-columns: repeat(4, 1fr); + grid-template-columns: repeat(5, 1fr); gap: 10px; }