Intermediate Algorithm Scripting - Sum All Numbers in a Range

Tell us what’s happening:
it works on single digit but not on double digits :frowning:
Please what do u think ?

  **Your code so far**
function sumAll(arr) {
let z = 0 
arr.sort()
for (let i = arr[0] ; i<=arr[1]; i++  ) {
z += i
}
return z
}


it works on single digit but not on double digits  :( 
Please what do u think ?

console.log(sumAll([5,10]))
  **Your browser information:**

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

Challenge: Intermediate Algorithm Scripting - Sum All Numbers in a Range

Link to the challenge:

Is this doing what you think it is doing? I would add some console.logs to check what’s going on aroung here

1 Like
2 Likes

what is your issue, it will help others to help you

@jasper2 The user did ask a question.

sorry i dont see it, where is it?

Make sure to read all the topic text (even if it appears in the code section).

**arr.sort((a,b) => a-b)**;

Thank you so much for all replies ,
.sort () missunderstanded me . It accepts the numbers like a string so, i had to show how its done with that function .