I dont understand this...can anyone help me out wid this question's answer!!?the answer is 4 bt don't knw how!!? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

I dont understand this...can anyone help me out wid this question's answer!!?the answer is 4 bt don't knw how!!?

function f(x){ if x==4 return 4; else return f(x+1); } alert(f(1));

6th Aug 2019, 2:28 PM
Christo Sam
Christo Sam - avatar
3 Answers
+ 2
It's recursion here => a function which calls itself until the base case is reached (base case is defined => x==4). So steps are f(2)=>f(3)=> and finally when x==4 => function returns 4.
6th Aug 2019, 3:01 PM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar
0
Thank u so much TheWh¡teCat 😊
7th Aug 2019, 4:08 AM
Christo Sam
Christo Sam - avatar
0
You are welcome Christo Sam 😉
7th Aug 2019, 6:10 AM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar