I need help please!!!. I tried the summary calculator and there is a "undefined" between the outpout , how to remove it? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

I need help please!!!. I tried the summary calculator and there is a "undefined" between the outpout , how to remove it?

function Add(...num){ var sum = 0; for(l=0; l<num.length; l++){ sum = sum + num[l]; } console.log(sum) } console.log(Add(1,2,3)); console.log(Add(4,14,5,9,14)); console.log(Add(2,36));

3rd Sep 2021, 3:33 PM
Harena
Harena - avatar
4 Answers
+ 4
return sum
3rd Sep 2021, 3:57 PM
Simba
Simba - avatar
+ 1
Instead of writing console.log(sum) Write return sum It means whenever u call Add function sum will return
3rd Sep 2021, 4:15 PM
Pariket Thakur
Pariket Thakur - avatar
+ 1
Thank you everyone , i just solved it after i posted this 😅😅😅
4th Sep 2021, 11:55 AM
Harena
Harena - avatar
0
Hey, could you paste that into a code bit and link it here? Makes it easier for all of us thank you ^^
3rd Sep 2021, 3:50 PM
Lennart Krauch
Lennart Krauch - avatar