diff --git a/src/functions-and-arrays.js b/src/functions-and-arrays.js index 3a7dbec..c2d478f 100644 --- a/src/functions-and-arrays.js +++ b/src/functions-and-arrays.js @@ -1,19 +1,46 @@ // Iteration #1: Find the maximum -function maxOfTwoNumbers() {} +function maxOfTwoNumbers(num1,num2) { + if(num1>num2){ + return num1; + } + else{ + return num2; + } + +} +let result=maxOfTwoNumbers(2,4) +console.log("The maximum number is:"+result); // Iteration #2: Find longest word const words = ['mystery', 'brother', 'aviator', 'crocodile', 'pearl', 'orchard', 'crackpot']; -function findLongestWord() {} +function findLongestWord() { + let longestWord='' + for(let i=0;ilongestWord.length){ + longestWord=words[i] + } + } + return longestWord; +} + +console.log(findLongestWord(words)) // 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