From 6d5514c2b96a21be3c27d44f05a89f93de9910e9 Mon Sep 17 00:00:00 2001 From: heco2900 Date: Sun, 29 May 2022 22:06:38 -0500 Subject: [PATCH] fixed multiplication, division, module functions --- .vscode/settings.json | 3 +++ index.html | 8 ++++---- main.js | 30 ++++++++++++++++++++---------- 3 files changed, 27 insertions(+), 14 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..f673a71 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "liveServer.settings.port": 5502 +} \ No newline at end of file diff --git a/index.html b/index.html index 063ab98..befa8b5 100644 --- a/index.html +++ b/index.html @@ -4,7 +4,7 @@ - + Document @@ -18,9 +18,9 @@ - - - + + +
diff --git a/main.js b/main.js index bf60c18..72a74b7 100644 --- a/main.js +++ b/main.js @@ -30,15 +30,20 @@ const subtract = (numA, numB) => { // These variables are already defined but that don't point to functions. It's up to you to build the functions to complete your calculator use: const multiply = (numA, numB) => { - // * to get a product then return it - // Open up the inspector tool in Chrome and select the Console tab to see what this functions is "logging out" to the console. - console.log(numA, numB) + const multiply = numA * numB + return multiply } -const divide = null -// / to get a quotient, +const divide = (numA, numB) => { + const divide = numA / numB + return divide +} + +const modulus = (numA, numB) => { + const modulus = numA % numB + return modulus +} -const modulus = null // and % to get a remainder. // This function changes the "operation" variable to be equal to the "id" of the button we choose on the web page. @@ -61,14 +66,19 @@ const putResultInElement = (operationResults) => { const equals = () => { switch (operation) { case "addition": putResultInElement(add(firstNum, secondNum)) + console.log(add(firstNum, secondNum)) break; - case "subtraction": putResultInElement(subtract(firstNum, secondNum)) + case "subtraction": putResultInElement(subtract(firstNum, secondNum)) + console.log(subtract(firstNum, secondNum)) break; - case "multiplication": multiply(firstNum, secondNum) + case "multiplication": putResultInElement(multiply(firstNum, secondNum)) + console.log(multiply(firstNum, secondNum)) break; - case "division": console.log(divide(firstNum, secondNum)) + case "division": putResultInElement(divide(firstNum, secondNum)) + console.log(divide(firstNum, secondNum)) break; - case "modulus": console.log(modulus(firstNum, secondNum)) + case "modulus": putResultInElement(modulus(firstNum, secondNum)) + console.log(modulus(firstNum, secondNum)) break; default: "Choose an operation" }