I'm attempting to create a function that identifies the largest number in an array, but for some reason, I'm only able to retrieve the first number in the array.
function findLargest(numbers) {
var bigNum = 1;
for(i = 0; i < numbers.length; i++) {
if(numbers[i] > bigNum) {
bigNum = numbers[i];
}
return bigNum;
}
}
var numbers = [3, 4, 2, 6, 45, 775, 83, 5, 7];
findLargest(numbers);