//1. extendObject
takes in an object, property, and value as parameters and adds the property and value to the object.
If the property already exists, overwrite its current value with the new value.
Return the object to the user.
Example:
var obj = {name: 'Barack'}
extendObject(obj, 'lastName', 'Obama')
console.log(obj) // {name: 'Barack', lastName: 'Obama'}
//2. findTarget
takes in two parameters, an object, and a target, and returns the target if it corresponds with a property inside of the object.
If not, it returns 'target not found' to the user.
Example:
var hobbit = {name: 'Bilbo Baggins', adventurer: true}
console.log(findTarget(hobbit, 'crazy')) // 'target not found'
console.log(findTarget(hobbit, 'adventurer')) // adventurer
//3. allNumbersEven
is a function that takes in an array of numbers as a parameter
Iterates through an array and returns true if every number is even
Otherwise, return false
Example:
var testTrue = [2,4,6,8]
vat testFalse = [2,4,5,8]
console.log(allNumbersEven(testTrue)) // true
console.log(allNumbersEven(testFalse)) // false
//4. titleCaseString
returns a string with the first letter of each word capitalized. Make sure the rest of the word is in lower case.
Example:
titleCaseString("Shanna can do a handstand, Kristina can't"); // Shanna Can Do A Handstand, Kristina Can't
//5. Create a function named first
that takes in an array as the first parameter and returns the first element in the array.
Your function also takes in a number as an optional second parameter. If a number is passed in as the second argument, you must return that number of elements in the array.
Example:
var nums = [1, 2, 3, 4, 5];
var getFirstNum = first(nums);
console.log("First element of the nums array: ", getFirstNum); // 1
var getFirstTwoNums = first(nums, 2);
console.log("First two elements of the nums array: ", getFirstTwoNums); // [1, 2]
First of all, we are going to create a test function called "assert".
With it we are going to test all the functions that we are going to build today, this function takes two parameters: an expression
(that evaluates to a boolean value) and a string
that describes the expected behavior:
- If the expression evaluates to true, return "test passed".
- Otherwise, return the string that describes the behavior.