Design a Sum All Numbers Algorithm

Tell us what’s happening:

it says that minNum isn’t defined when it clearly is???

My code so far

function sumAll(arrOf2) {
  minNum = Math.min(...arrOf2);
  maxNum = Math.max(...arrOf2);
  let sum = 0;
  for (let i = minNum; i <= maxNum; i++) {
    sum += i;
  };
  return sum;
}
console.log(sumAll([1,4]))
console.log(sumAll([4,1]))
console.log(sumAll([5,10]))
console.log(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/138.0.0.0 Safari/537.36

Challenge Information:

Design a Sum All Numbers Algorithm - Design a Sum All Numbers Algorithm

this code runs perfectly fine when I run it on other compilers, such as Programiz

where is it defined?

your Programiz does not run in strict mode, you can add strict mode adding 'use strict' on the first line of the editor

how does Strict modes make a difference here?

I forgot to use let for the variables :man_facepalming:
thanks for pointing this out, seems like I’m waaay too used to Python’s syntax

1 Like

do you understand now how strict mode makes a different now?

yeah, it seems as if Sloppy Mode (which must’ve been what the default was on Programiz) allows errors like that to slide, whereas Strict Mode doesn’t

1 Like