Help me understand what's wrong here please :)

Tell us what’s happening:
Describe your issue in detail here.

Why doesn’t my code pass the automated tests?? When I console.log typeof ‘variable’ it does say ‘number’, when I console.log the input examples I do get the correct output… Can someone tell me what’s wong here:

  **Your code so far**

function sumAll(arr) {
let y = [];
let x = arr.slice()
x = x.sort((a, b) => a - b);
y.push(x[0]);
let z = x.reduceRight((b, a) => b - a);
for (let i = 1; i < z; i++) {
  y.push(x[0] + i)
}
y.push(x[1]);
y = y.reduce((a, b) => a + b);
console.log(y);
}

sumAll([10, 5]);
  **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36

Challenge: Sum All Numbers in a Range

Link to the challenge:

What is your function returning. I think you are getting the right answer, but you aren’t returning it from the function.

When I fix that, your code passes for me.

hehehe you’re right. Thank you so much. I wasn’t seeing it!!!

Get used to it. Part of being a dev is making silly little mistakes and then feeling like an idiot. The mistakes get more subtle and you’ll get better at finding them, but they never go away completely.

1 Like