diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 000000000..c3df2e669 Binary files /dev/null and b/.DS_Store differ diff --git a/starter-code/src/functions-and-arrays.js b/starter-code/src/functions-and-arrays.js index 2fcd81e6e..7ed123254 100644 --- a/starter-code/src/functions-and-arrays.js +++ b/starter-code/src/functions-and-arrays.js @@ -1,5 +1,14 @@ // Find the maximum +function maxOfTwoNumbers(num1, num2) { + if(num1 > num2) + return num1; + else + return num2; +} + +maxOfTwoNumbers(25,22); + // Finding Longest Word var words = [ 'mystery', @@ -10,15 +19,44 @@ var words = [ 'orchard', 'crackpot' ]; +function findLongestWord(words) { + if(words.length === 0){ + return undefined + } + let longestWord = 0; + let longestName = ""; + for(let i = 0; i < words.length; i++){ + if(words[i].length > longestWord){ + longestWord = words[i].length; + longestName = words[i]; + } + } + + return longestName; + +} // Calculating a Sum - var numbers = [6, 12, 1, 18, 13, 16, 2, 1, 8, 10]; -// Calculate the Average +function sumArray(arr){ + let sumNumbers=0; + for (i=0; i