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.

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?

@admit8490 yes sure. Here you go:

@camperextraordinaire I also tried to call
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 .

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