Skip to content
Open
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
64 changes: 51 additions & 13 deletions js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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!

/////////////////////////////////////
Expand All @@ -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!

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

Expand All @@ -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<sumArr.length;i++) {
sum += sumArr[i];
}
let str = sumArr.toString() + ' was passed in as an array of numbers, and ' + sum + ' is their sum.';
newArr.push(sum);
newArr.push(str);

// console.log(sumArr.toString() + ' was passed in as an array of numbers, and ' + sum + ' is their sum.');
return newArr;
}







// Here is the test for sumArray(); uncomment it to run it

// testSumArray(testArray);
testSumArray(testArray);

// 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!

Expand All @@ -95,9 +132,10 @@ 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
}


// Here is the test for multiplyArray(); uncomment it to run it
// testMultiplyArray(testArray);

Expand Down