Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{
}
31 changes: 29 additions & 2 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;

}

Expand All @@ -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
Expand All @@ -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
Expand Down