Home > database >  Browser can't process the code, how can I fix it?
Browser can't process the code, how can I fix it?

Time:09-26

i've been trying to take an array and use it to find the largest area in it (using array as height and length between array variables as width) but when i try to launch it the page simply won't load, how can i fix it?

var array = [1, 8, 6, 2, 5, 4, 8, 3, 7];

var height, width, area; var maxArea = 0;

function largestArea () {

for (i = 0; i < array.length; i  ){

    for (n = i 1; n = array.length - 2; n  ) {

        if (array[i] > array[n]) {
            height = array[n];
        }
        else if (array[i] = array[n]) {
            height = array[n];
        }
        else {
            height = array[i];
        }

        width = n - i;
        area = height * width;

        if (area > maxArea) {
            maxArea = area;
        }
    }
}

console.log(maxArea);

}

largestArea();

CodePudding user response:

The issue may be because you accidentally assigned n twice instead of using comparison as I think is want you really wanted:

for (n = i 1; n = array.length - 2; n ) {

CodePudding user response:

i haven't problem for loading your code. sure javascript enable in your browser and check your html code and sure tag be in the tag.


i must to comment on your post but my comment is'nt enable yet and i hove to answer your post, i'm sorry

  • Related