Tests failed to run due to an error: "". Check your code and try again

Hello Im trying to resolve Maximize Stock Trading Profit challange and I keep having the same issue Tests failed to run due to an error: “”. Check your code and try again.. Im totally stucked.

Given the daily values of a stock, create a function called maxProfitDays() that, given a list of integers, will return the index value of the two elements that represent the day on which one should have bought a share and the day on which one should have sold a share based on the max profit.

A list of integers will represent the stock price at the beginning or “opening bell” of each day for a week. You are required to buy and sell only once. You also must buy a stock before selling it.

For example, given the list [17, 11, 60, 25, 150, 75, 31, 120], you can assume that index 0 represents day 0 and index 7 represents day 7. In this case, purchasing on day 1 and selling on day 4 would yield the most profit. If we were to call maxProfitDays([17, 11, 60, 25, 150, 75, 31, 120]), the function would return [1, 4].

function maxProfitDays (profitDays) { let profit = 0; let index = 0; for (let i= 0; i<profitDays.length; i++) { for (let j=i; j<profitDays.length; j++) { if (profitDays[j]-profitDays[i]>profit) { profit = profitDays[j]-profitDays[i]; index = [i , j] } } } return console.log (index) } const list = [17, 11, 60, 25, 150, 75, 31, 120] maxProfitDays(list)

console.log does not return anything, it just makes stuff print out to the console/screen.
so
return console.log (index)
should be
return index
or
console.log (index)
return index

Note that sometimes there are problems with the tests for the challenges if there are any console.log in the code.

Yes it was my first option, I tried many ways, always the same error

Based on the image you just posted, you appear to have removed the code that performs the test. Put this line back in:

// Leave this so we can test your code:
module.exports = maxProfitDays;

and correct the returning of the index variable as @janbazant1107978602 indicated and you should be fine.

Oh I missed that detail thank youuuuuuuu so much!

mega, this code challenge works for you now?

I’m getting the same error. I did this off-platform and it works just fine but it isn’t running for me in the codecademy environment. Even if I just replace all my code with a console.log('Hello World'); nothing prints to the console and the tests can’t be run. I did not delete the export of the function, so that’s not the issue.

Other code challenges seem to work fine.