diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..7a73a41 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,2 @@ +{ +} \ No newline at end of file diff --git a/app.js b/app.js index 792e13b..93d8b01 100644 --- a/app.js +++ b/app.js @@ -13,7 +13,12 @@ Test this function by hand in the console to get it working, and when you think // Write your code here function sum(a, b) { + var result = a + b; + var array = [result]; + + array[1] = "The sum of " + a + " and " + b + " is " + result; + return array; } // Here is the test for sum(); uncomment it to run it @@ -31,6 +36,12 @@ Test this function by hand in the console to get it working, and when you think // Write your code here function multiply(a, b) { + var product = a * b; + var array = [product]; + + + array[1] = "The product of " + a + " and " + b + " is " + product; + return array; } @@ -51,8 +62,16 @@ IMPORTANT DETAIL: You may not use the arithmetic operators + and * in this funct Test this function by hand in the console to get it working, and when you think it is finished, uncomment the call for the testSumAndMultiply() function and see if the test passes.*/ // Write your code here -function sumAndMultiply(a, b, c) { +function sumAndMultiply(a, b, c) { + var absum = sum(a, b); + absum =sum(absum[0], c); + var array = [absum[0]]; + var abmul = multiply(a, b); + abmul = multiply(abmul[0], c); + array[1] = abmul[0]; + array[2] = "The sum of " + a + ", " + b + " and " + c + " is " + array +"."; + array[3] = "The product of " + a + ", " + b + " and " + c + " is " + array[1] + "."; } // Here is the test for sumAndMultiply(); uncomment it to run it @@ -72,7 +91,15 @@ Test this function by hand in the console to get it working, and when you think // Write your code here function sumArray(sumArr) { - + var sSum = []; + sSum[0] = sum(sumArr[0], sumArr[1])[0]; + var i = 2; + while (i<(sumArr.length)){ + sSum[0] = sum(sSum[0], sumArr[i])[0]; + i++; + } + sSum = sumArr + ' was passed in as an array of numbers, and ' + sSum + ' is their sum.'; + return sSum; } // Here is the test for sumArray(); uncomment it to run it