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!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 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 Respostas
+ 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