diff --git a/js/app.js b/js/app.js index 778aeb1..af3f5d8 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