# How to find a largest number in an array?

```function myarray(min, max) {
var points = [];
for (var i = 0; i < 10; i++) {
points.push(Math.round(Math.random() * (1000 - 100 + 1) + 100));
points.join('<br>');
var largest = Math.max.apply(0, points);
}
return points
}

console.log(myarray());```

My task is pretty simple, I want to create 10 random numbers from 1 to 1000 in an array and then print the highest one. I think I am pretty close but when I run this I get `undefined`.

How can I fix this? and what is undefined?

You can compare `points` to the largest number. Try the below snippet.

```function myarray(min, max) {
var points = [];
var largest = 0;
for (var i = 0; i < 10; i++) {
points.push(Math.round(Math.random() * (1000 - 100 + 1) + 100));
if ( points[i] > largest ) {
var largest = points[i];
}
}
console.log(points);
console.log(largest);
}
myarray();```

As per OP comment.

```function myarray(min, max) {
var points = [ 521,338,761,834,561,842,177,862,173 ];
var largest = 0;
for (var i = 0; i < 10; i++) {
if ( points[i] > largest ) {
var largest = points[i];
}
}
console.log(points);
console.log(largest);
}
myarray();```