Skip to content

Commit

Permalink
Functionalities of . changed
Browse files Browse the repository at this point in the history
  • Loading branch information
shivangi-singhjha committed May 24, 2024
1 parent 7037883 commit d7371c9
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 359 deletions.
18 changes: 0 additions & 18 deletions Calculators/Basic-Calculator-2.0/README.md

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.
55 changes: 0 additions & 55 deletions Calculators/Basic-Calculator-2.0/index.html

This file was deleted.

78 changes: 0 additions & 78 deletions Calculators/Basic-Calculator-2.0/script.js

This file was deleted.

192 changes: 0 additions & 192 deletions Calculators/Basic-Calculator-2.0/style.css

This file was deleted.

2 changes: 1 addition & 1 deletion Calculators/Basic-Calculator/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<span class="num" onclick="calc.txt.value += '6' "><i>6</i></span>
<span class="num" onclick="calc.txt.value += 'Math.sqrt(' "><i></i></span>
<span class="num" onclick="calc.txt.value += '%' "><i>%</i></span>
<span class="num" onclick="calc.txt.value += '.' "><i>.</i></span>
<span class="num point" onclick="point()"><i>.</i></span>
<span class="num" onclick="calc.txt.value += '1' "><i>1</i></span>
<span class="num" onclick="calc.txt.value += '2' "><i>2</i></span>
<span class="num" onclick="calc.txt.value += '3' "><i>3</i></span>
Expand Down
30 changes: 30 additions & 0 deletions Calculators/Basic-Calculator/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ let calc = document.forms["calc"];
let txt = calc.elements["txt"];
let math = window.math;
let display = document.getElementById("display");
// let zero = document.getElementById("display");


document.addEventListener("keydown", function (event) {
const validKeys = /^[0-9.\+\-\*\/\(\)\^\%\{\}\[\]&]$/;
Expand Down Expand Up @@ -46,3 +48,31 @@ function clearOne() {
let currentValue = calc.txt.value;
calc.txt.value = currentValue.slice(0, -1);
}

function point() {
let currentValue = calc.txt.value;
if (currentValue == "") {
calc.txt.value = '0' + '.';
}
else {

if (currentValue.charAt(currentValue.length - 1) == "." || currentValue.charAt(currentValue.length - 1) == "(") {
calc.txt.value = calc.txt.value + '0' + '.';
return;
}
if (currentValue.charAt(currentValue.length - 1) == "+" ||
currentValue.charAt(currentValue.length - 1) == "*" ||
currentValue.charAt(currentValue.length - 1) == "-" ||
currentValue.charAt(currentValue.length - 1) == "/" ||
currentValue.charAt(currentValue.length - 1) == "%" ||
currentValue.charAt(currentValue.length - 1) == "√" ||
currentValue.charAt(currentValue.length - 1) == "^") {
calc.txt.value = calc.txt.value + '0' + '.';
return;
}
else {
calc.txt.value = calc.txt.value + ".";
return;
}
}
};
Loading

0 comments on commit d7371c9

Please sign in to comment.