From a7bd7d6262cbfffa5a8a078a3146d4db6c5b6cb9 Mon Sep 17 00:00:00 2001 From: mahad Ali Date: Sun, 21 Aug 2022 00:35:47 -0700 Subject: [PATCH 1/2] saved 4th question --- js/app.js | 62 ++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 50 insertions(+), 12 deletions(-) diff --git a/js/app.js b/js/app.js index 778aeb1..df83a38 100644 --- a/js/app.js +++ b/js/app.js @@ -9,14 +9,16 @@ Test this function by hand in the console to get it working, and when you think // Write your code here function sum(a, b) { //eslint-disable-line -let result = a + b; - -return [result, "The sum of 4 and 7 is 11."]; + let result = a + b; + let string = 'The sum of ' + a + ' and ' + b + ' is ' + result + '.'; + console.log([result, string]); + return [result, string]; } // Here is the test for sum(); uncomment it to run it - testSum(4, 7); - +testSum(4, 7); +//testSum(10,20); +//console.log(testSum(10,20)); // Once you get the test passing, do an a-c-p cycle and synchronize the code between GitHub and your laptop. Don't forget to create a new branch for your work on the next question! ///////////////////////////////////// @@ -29,13 +31,13 @@ Test this function by hand in the console to get it working, and when you think // Write your code here function multiply(a, b) { //eslint-disable-line -let result = a * b; - -return [result, "The product of 5 and 9 is 45."]; + let result = a * b; + let string = 'The product of ' + a + ' and ' + b + ' is ' + result + '.'; + return [result, string]; } // Here is the test for multiply(); uncomment it to run it - testMultiply(5,9); +testMultiply(5,9); // Once you get the test passing, do an a-c-p cycle and synchronize the code between GitHub and your laptop. Don't forget to create a new branch for your work on the next question! @@ -53,10 +55,28 @@ Test this function by hand in the console to get it working, and when you think // Write your code here function sumAndMultiply(a, b, c) { //eslint-disable-line + let sumAB = sum(a, b)[0]; + let sumABC = sum(sumAB, c)[0]; + let multiplyAB = multiply(a,b)[0]; + console.log(multiplyAB); + let multiplyABC = multiply(multiplyAB, c)[0]; + console.log(multiplyABC); + + //console.log(multiplyAB, multiplyABC); + let res1 = a + ' and ' + b + ' and ' + c + ' sum to ' + sumABC + '.'; + let res2 = 'The product of ' + a + ' and ' + b + ' and ' + c + ' is ' + multiplyABC + '.'; + + + let result = [sumABC,multiplyABC, res1, res2]; + console.log('result is ', result); + return result; + + } + // Here is the test for sumAndMultiply(); uncomment it to run it -// testSumAndMultiply(4,7,5); +testSumAndMultiply(4,7,5); // Once you get the test passing, do an a-c-p cycle and synchronize the code between GitHub and your laptop. Don't forget to create a new branch for your work on the next question! @@ -71,15 +91,32 @@ IMPORTANT DETAIL: You may not use the arithmetic operator + in this function. To Test this function by hand in the console to get it working, and when you think it is finished, uncomment the call for the testSumArray() function and see if the test passes.*/ // Write your code here -let testArray = [2, 3, 4]; //eslint-disable-line +let testArray = [2,3,4]; //eslint-disable-line function sumArray(sumArr) { //eslint-disable-line + let newArr = []; + let sum = 0; + for (let i=0; i Date: Sun, 21 Aug 2022 12:11:40 -0700 Subject: [PATCH 2/2] saved 4th --- js/app.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/app.js b/js/app.js index df83a38..af3f5d8 100644 --- a/js/app.js +++ b/js/app.js @@ -132,7 +132,7 @@ Test this function by hand in the console to get it working, and when you think // Write your code here function multiplyArray(multArr) { //eslint-disable-line - +let }