Maximum pairwise product

Hi , I am currently working on this problem but could not be able to get the output. How caniI use an array of integers of my desired numbers?
Here is my code. I tried
console.log( maxproduct([1,2,3])); but no luck yet.
PLEASE HELP !!!

function max(arr) {
    // write your code here
    let product = 0;
    
    for (let i=0; i<arr.length; i++){
        for(let j= i+1; j<arr.length; j++){
         let maxProduct= arr[i] * arr[j];
          if (maxProduct > product){
            maxProduct = product
          }
        }
    }

  return maxProduct;
};

Can you give a link to this task? It’s from code prep section I guess?

Well for starters, you have not defined a function named maxproduct to be able to call it as you are doing above.

@admit8490 yes sure. Here you go: https://codepen.io/naimiii/pen/OJvoogV?editors=1111

@RandellDawson I also tried to call
console.log(max([1,2,3]));
But no luck yet…
What should I do? :frowning:

I think you have some confusion going on with variables.

It seems that you are using product to store result.

However, you are returning maxProduct

And there are some assigning in the loop which doesn’t make much sense:

Do you really want to assign product value to maxProduct here?

And one more little thingy(maybe a spoiler): do you really need to get every possible product here? You can just find two biggest numbers in this array, and get their product.

I only wanna store the result of maxProduct variable to the product variable .