# Return the Largest number array challenge

Hello There,

Here is my code, I’m unsure what exactly is wrong is keeps saying the variable that I declared is undefined.

``````function largestOfFour(arr) {
// You can do this!
let largest = [];
var highestNumber = 0;
for (let i = 0; i < arr.length; i++) {
for (let j = 0; j < arr[i].length; j++) {
if (arr[i][j] > highestNumber)
highestNumber = arr[i][j];
}
largest.push(highestNumber);
}
return largest;
}

console.log(largest);
``````
1 Like
``````console.log(largest);
``````

That variable largest doesn’t exist at that point. It exists inside largestOfFour, it’s “scope”.

You need access it through your function, like this:

``````function largestOfFour(arr) {
// You can do this!
let largest = [];
var highestNumber = 0;
for (let i = 0; i < arr.length; i++) {
for (let j = 0; j < arr[i].length; j++) {
if (arr[i][j] > highestNumber)
highestNumber = arr[i][j];
}
largest.push(highestNumber);
}
return largest;
}

console.log(largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]));
``````
1 Like