From 2087dece320791de277f2f5513fcebe39464d212 Mon Sep 17 00:00:00 2001 From: Mrazo04 Date: Wed, 15 Feb 2023 19:26:24 -0600 Subject: [PATCH 1/3] cloned folder --- style.css => index.css | 0 main.js => index.js | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename style.css => index.css (100%) rename main.js => index.js (100%) diff --git a/style.css b/index.css similarity index 100% rename from style.css rename to index.css diff --git a/main.js b/index.js similarity index 100% rename from main.js rename to index.js From a48fef3229d4828d11deb9f2f40cd1e9615997d0 Mon Sep 17 00:00:00 2001 From: Mrazo04 Date: Mon, 20 Feb 2023 00:01:56 -0600 Subject: [PATCH 2/3] created calculator --- index.html | 8 ++++---- index.js | 17 +++++++++++++++-- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/index.html b/index.html index 063ab98..366bb8c 100644 --- a/index.html +++ b/index.html @@ -4,7 +4,7 @@ - + Document @@ -18,9 +18,9 @@ - - - + + +
diff --git a/index.js b/index.js index bf60c18..b743a84 100644 --- a/index.js +++ b/index.js @@ -30,12 +30,18 @@ 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) => { + const product = numA * numB + return product // * 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 divide = null +const divide = (numA, numB) => { + const quotient = numA/numB + return quotient +} + // / to get a quotient, const modulus = null @@ -59,6 +65,13 @@ const putResultInElement = (operationResults) => { // The function uses the value of "operation" variable to determine which operation function it should use on the number: add, subtract, multiply, divide, or modulus const equals = () => { + if (!firstNum) { + firstNum = parseInt(document.getElementById("first-Number").value) + } + + if (!secondNum) { + secondNum = parseInt(document.getElementById("second-Number").value) + } switch (operation) { case "addition": putResultInElement(add(firstNum, secondNum)) break; @@ -70,7 +83,7 @@ const equals = () => { break; case "modulus": console.log(modulus(firstNum, secondNum)) break; - default: "Choose an operation" + default: alert("Choose an operation") } } From 44740db366d7ce58e0e7f1c3d0bf93c3e215a75e Mon Sep 17 00:00:00 2001 From: Mrazo04 Date: Mon, 20 Feb 2023 01:05:10 -0600 Subject: [PATCH 3/3] got all functions to work. pending console log --- index.js | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/index.js b/index.js index b743a84..6580f98 100644 --- a/index.js +++ b/index.js @@ -30,21 +30,24 @@ 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) => { - const product = numA * numB - return product + const multiply = (numA * numB) + return multiply // * 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 divide = (numA, numB) => { - const quotient = numA/numB - return quotient + const divide = (numA / numB) + return divide } // / to get a quotient, -const modulus = null +const modulus = (numA, numB) => { + const modulus = (numA % numB) + return modulus +} + // 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. @@ -72,16 +75,18 @@ const equals = () => { if (!secondNum) { secondNum = parseInt(document.getElementById("second-Number").value) } + + console.log(firstNum, secondNum); switch (operation) { case "addition": putResultInElement(add(firstNum, secondNum)) break; case "subtraction": putResultInElement(subtract(firstNum, secondNum)) break; - case "multiplication": multiply(firstNum, secondNum) + case "multiplication": putResultInElement(multiply(firstNum, secondNum)) break; - case "division": console.log(divide(firstNum, secondNum)) + case "division": putResultInElement(divide(firstNum, secondNum)) break; - case "modulus": console.log(modulus(firstNum, secondNum)) + case "modulus": putResultInElement(modulus(firstNum, secondNum)) break; default: alert("Choose an operation") }