Return largest number in array

//Hi I’m trying to figure out what’s wrong with my code when I’m trying to return the largest number in an array
//Example. findMax[0,200,1,5,3] should return 200

function findMax(n){
  var max = 0;
  for (var i = 0; i < n.length; i++){
    if (n[i] > max){
      var max = n[i];
  return max;

The variable is declared before the loop so should not use a var keyword inside the loop.

findMax[0,200,1,5,3] should return 200

should be,


Thank you so much for your help!


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.