diff --git a/src/functions-and-arrays.js b/src/functions-and-arrays.js index 3a7dbec..871d181 100644 --- a/src/functions-and-arrays.js +++ b/src/functions-and-arrays.js @@ -1,24 +1,51 @@ // Iteration #1: Find the maximum -function maxOfTwoNumbers() {} - +function maxOfTwoNumbers(num1,num2) { + if(num1>num2){ + return num1; + } + else{ + return num2; + } +} +const result1= maxOfTwoNumbers(10,2); +console.log(result1); // Iteration #2: Find longest word const words = ['mystery', 'brother', 'aviator', 'crocodile', 'pearl', 'orchard', 'crackpot']; -function findLongestWord() {} +function findLongestWord() { + let longestw =""; + for(let i=0;i longestw.length){ + longestw=words[i]; + } + } + return longestw; +} +const result2 = findLongestWord(); +console.log(result2); // Iteration #3: Calculate the sum const numbers = [6, 12, 1, 18, 13, 16, 2, 1, 8, 10]; - -function sumNumbers() {} +function sumNumbers() { + let sum =0; + for(let i=0;i