+ 1

Please help with this code coach

function Add(input){ let num = 0; for (let i of input){ num += i; } return num; } console.log(Add(1,2,3)); console.log(Add(4,14,5,9,14)); console.log(Add(2,36)); Whats wrong?!

14th Nov 2022, 11:36 AM
Ugulberto SĂĄnchez
Ugulberto SĂĄnchez - avatar
5 Answers
+ 1
Is that solution given by Sololearn? Where? Can you add details..
14th Nov 2022, 12:07 PM
Jayakrishna 🇼🇳
+ 2
You are passing multiple values but function has a single variable of primitive type. Change function parameter to as array (...input) Or pass values as an array by using [ ] braces like : console.log(Add( [1,2,3] ))
14th Nov 2022, 11:53 AM
Jayakrishna 🇼🇳
0
Ah, thanks
14th Nov 2022, 11:54 AM
Ugulberto SĂĄnchez
Ugulberto SĂĄnchez - avatar
0
So the solution of the sololearn code coach is wrong?
14th Nov 2022, 11:55 AM
Ugulberto SĂĄnchez
Ugulberto SĂĄnchez - avatar
0
Yes the solution given in “Rest and Spread” lesson in EcmaScript 6. The solution is wrong. Look at it.
14th Nov 2022, 12:09 PM
Ugulberto SĂĄnchez
Ugulberto SĂĄnchez - avatar