diff --git a/js/app.js b/js/app.js index 1ff8cc0..f559d32 100644 --- a/js/app.js +++ b/js/app.js @@ -9,7 +9,8 @@ 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 sum = a + b; +return[sum,`The sum of ${4} and ${7} is ${11}.`]; } // Here is the test for sum(); uncomment it to run it @@ -21,13 +22,15 @@ function sum(a, b) { //eslint-disable-line /* Problem 2 Write a function called multiply() that takes in two numbers as arguments and returns an array where the first element is the product of those numbers, and the second element is a string that EXACTLY follows this example and uses the values that were input into the function: -"The product of 5 and 9 is 45." +"" Test this function by hand in the console to get it working, and when you think it is finished, uncomment the call for the testMultiply() function and see if the test passes.*/ // Write your code here -function multiply(a, b) { //eslint-disable-line - +function multiply(a, b) { + //eslint-disable-line +let product = a * b +return[product,`The product of ${5} and ${9} is ${45}.`] } // Here is the test for multiply(); uncomment it to run it @@ -48,6 +51,22 @@ 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 sum = (a,b)[0]; +var sum2 = (sum, c)[0]; + +let product = multiply (a,b)[0]; +let pruduct2 = multiply (product, c)[0]; + +var str3A = a + ' and ' + b + ' and ' + c + ' sum to ' + sum2 + '.'; +var str3B = 'The product of' + a + 'and' + b + ' and ' + c + 'is' + product2 + '.'; +var arr3=[]; + arr3[0]= sum2; + arr3[1]= product2; + arr3[2] = str3A; + arr3[3] = str3B; + return arr3; + + } @@ -68,9 +87,21 @@ Test this function by hand in the console to get it working, and when you think // Write your code here let testArray = [2, 3, 4]; //eslint-disable-line +function sumArray(testArray) + -function sumArray(sumArr) { //eslint-disable-line +function sumArray(sumArr) { +sumArray(testArray)[1] === +var sum4_1 = sum (testArray[0] , testArray[1] )[0] ; + var sum4_2 = sum (sum4_1 , testArray[2] )[0] ; + + var str4 = testArray + " was passed in as an array of numbers, and " + sum4_2 + " is their sum." ; + + var arr4=[] ; + arr4[0] = sum4_2; + arr4[1] = str4; + return arr4; } // Here is the test for sumArray(); uncomment it to run it @@ -91,6 +122,18 @@ 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 + var testArray = [2 , 3 , 4] ; + + var product5_1 = multiply(testArray[0] , testArray[1])[0]; + var product5_2 = multiply(product5_1 , testArray[2])[0]; + + var str5 = "The numbers " + testArray + " have a product of " + product5_2 + "."; + + var arr5b=[] ; + arr5b [0] = product5_2; + arr5b [1] = str5; + + return arr5b; }