Works in VSCode but not in freecodecamp?

Tell us what’s happening:
I’m getting “ReferenceError: assignment to undeclared variable sum” in the freecodecamp environment but it works in visual studio code.

I’ve found the solution that works for freecodecamp:

“const sum = second =>
typeof second === “number” ? args[0] + second : undefined
return sum”

can anyone explain the discrepancy and which version is more correct?

many thanks!

Your code so far


function addTogether() {
let args = Array.from(arguments)
if (!args.every(elem => typeof(elem) === "number"))
  return undefined

if (args.length > 1)
  return args.reduce((acc, cur) => acc + cur)

return sum = second =>
  typeof second === "number" ? args[0] + second : undefined
}


console.log(addTogether(2)(3))
addTogether(2,3);

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:76.0) Gecko/20100101 Firefox/76.0.

Challenge: Arguments Optional

Link to the challenge:

freeCodeCamp challenges run in Strict Mode. If you are working on code outside of the freeCodeCamp editor, you should also enable Strict Mode.

1 Like

You can just return an anonymous function instead.

return second =>
    typeof second === "number" ? args[0] + second : undefined;