Manipulating Function | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

Manipulating Function

Why is the output undefined even tho there is return statement. function david(small_head) { console.log(small_head); } function yusuff(brilliant, handsome) { let grillo = brilliant + handsome; return david(grillo); } console.log(yusuff(5,5));

1st Sep 2020, 1:25 PM
Ibrahim Yusuf
Ibrahim Yusuf - avatar
7 Answers
+ 1
Ibrahim Yusuf what you should do is: function david(xyz){ return xyz; /*in this case, you are telling the function to return the result/value of xyz whenever the function is called*/ /* using console.log() instead of a return here would make the function undefined, cos it means no values is assigned to it*/}; function yusuf(b,h){ let g = b + h; /* here, you are calling the function david inside of yusuf assigning the values/result from "g" to it as an argument, so a value would be returned*/ return david(g); } console.log(yusuf(5,5)); // i hope this helps.
1st Sep 2020, 4:41 PM
Infinite
Infinite - avatar
+ 3
Because the function david() didn't return any values. So that giveundefined.
1st Sep 2020, 2:05 PM
Vadivelan
+ 2
Infinite, Vadivelan Do I need to return david() if it's already printed inside the function? something like this: function david(xyz) { console.log(xyz); } david("Output"); even tho I didn't return david(), the output is still showing
1st Sep 2020, 2:41 PM
Ibrahim Yusuf
Ibrahim Yusuf - avatar
+ 2
Ibrahim Yusuf What do you want return from david()?
1st Sep 2020, 3:24 PM
Vadivelan
+ 2
Vadivelan Just want to get the output of both david() and yusuff();
1st Sep 2020, 4:55 PM
Ibrahim Yusuf
Ibrahim Yusuf - avatar
+ 2
Infinite Thank you, That reall helps
1st Sep 2020, 4:56 PM
Ibrahim Yusuf
Ibrahim Yusuf - avatar
+ 1
There is no return in david().
1st Sep 2020, 2:21 PM
Infinite
Infinite - avatar