diff --git a/README.md b/README.md index 5d11b9e6e..81bf62d26 100644 --- a/README.md +++ b/README.md @@ -93,7 +93,7 @@ Define a function `maxOfTwoNumbers` that takes two numbers as arguments and retu ## Finding Longest Word -Write a function `findLongestWord` that takes an array of words and returns the length of the longest one. If there are 2 with the same length, it should return the first occurrence. +Write a function `findLongestWord` that takes an array of words and returns the longest one. If there are 2 with the same length, it should return the first occurrence. **Starter Code** diff --git a/starter-code/src/functions-and-arrays.js b/starter-code/src/functions-and-arrays.js index 2fcd81e6e..d5d54f127 100644 --- a/starter-code/src/functions-and-arrays.js +++ b/starter-code/src/functions-and-arrays.js @@ -1,4 +1,12 @@ // Find the maximum +function maxOfTwoNumbers(x,y){ + if (x > y){ + return x; + }else{ + return y; + } + } + maxOfTwoNumbers(1,3) // Finding Longest Word var words = [ @@ -10,16 +18,51 @@ var words = [ 'orchard', 'crackpot' ]; +function findLongestWord (array) { -// Calculating a Sum +var longuestWord = "" +for (var i=0; i longuestWord.length){ + longuestWord= array[i] +} +} + +if (array.length === 0){ + return +} +return longuestWord; + + +} +findLongestWord(words) +// Calculating a Sum var numbers = [6, 12, 1, 18, 13, 16, 2, 1, 8, 10]; +function sumArray (array){ + var sum = 0; + for (i=0; i