Intermediate Algorithm Scripting - Sum All Numbers in a Range

Tell us what’s happening:

Describe your issue in detail here.
its not exactly a issue but i learned js in hs and its been two years since then, i decided to do this problem just off of memory, Just wanted to know am i close or do i go the right idea?

Your code so far

function sumAll(arr) {
  let sum = arr[0] + arr[1];
  let bsum = 0;
 if ( arr[0] < arr[1]){
   for(let i = arr[0];  i < arr[1]; i++){
     bsum += i;
    
   }
 }
 return sum + bsum;
}
sumAll([1, 4]);

Your browser information:

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

Challenge Information:

Intermediate Algorithm Scripting - Sum All Numbers in a Range

Can you explain what this if statement is for? I think it might be making more problems for you than its solving.

1 Like

it was suppose to be meant for if it wasless than it would go thtrew all numbers between 0 and 1 in the problem case it was 1 is 0 and 4 is 1. if it was the opposite i would have did i-- instead off i++

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