diff --git a/calculator/index.html b/calculator/index.html
index 19c3434..9151946 100644
--- a/calculator/index.html
+++ b/calculator/index.html
@@ -16,7 +16,7 @@
-
+
diff --git a/calculator/js/script.js b/calculator/js/script.js
index 32f26ff..6edbce6 100644
--- a/calculator/js/script.js
+++ b/calculator/js/script.js
@@ -92,6 +92,12 @@ function handleOperatorClick(operatorClicked) {
return;
} else if (operatorClicked === '=') {
handleOperation();
+ } else if (operatorClicked === '+/-') {
+ negateNumber();
+ return
+ } else if (operatorClicked === '%') {
+ percentageNumber();
+ return
} else {
if(ops.secondNum && ops.numFlag){
handleOperation();
@@ -121,6 +127,31 @@ function calculator(event){
}
}
+function negateNumber(){
+ // returns a negated number
+ let negated;
+ if (!ops.numFlag || !ops.onSecondNumber) {
+ negated = Number(ops.firstNum) * -1;
+ ops.firstNum = String(negated);
+ } else {
+ negated = Number(ops.secondNum) * -1;
+ ops.secondNum = String(negated);
+ }
+ updateDisplay(negated);
+}
+
+function percentageNumber() {
+ let percent;
+ if (!ops.numFlag || !ops.onSecondNumber) {
+ percent = Number(ops.firstNum) / 100;
+ ops.firstNum = String(percent);
+ } else {
+ percent = Number(ops.secondNum) / 100;
+ ops.secondNum = String(percent);
+ }
+ updateDisplay(percent);
+}
+
buttons.forEach(btn => {
btn.addEventListener('click', calculator);
});
\ No newline at end of file