Skip to content

Instantly share code, notes, and snippets.

@kosalvann
Last active September 23, 2015 10:51
Show Gist options
  • Save kosalvann/97a84337c3538f854b3e to your computer and use it in GitHub Desktop.
Save kosalvann/97a84337c3538f854b3e to your computer and use it in GitHub Desktop.
Define a function findLargestNumber() that takes an argument from a list of numbers as and returns the largest of them. Use the if condition to get the largest number from the list.
// Define a function findLargestNumber() that takes an argument
// from a list of numbers as and returns the largest of them.
// Use the if condition to get the largest number from the list.
// https://jsfiddle.net/3v3LoLrp/
function findLargestNumber(numbers){
var largestNum = 0 ;
for (var i = 0; i <= numbers.length; i++){
if (numbers[i] > largestNum){
largestNum = numbers[i];
}
}
return largestNum;
}
console.log(findLargestNumber([74, 39, 88, 57, 29, 17, 55, 72]));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment