How come the value of the code equals 337? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 5

How come the value of the code equals 337?

function mlt(a, b) { if(!a && b)) { return 0; } else if(b == 1 ) { return a; } else { return (a + mlt(a, b - 1)); } } document.write(mlt(3, 11)); document.write(mlt(7, 1));

7th Jul 2019, 1:58 PM
eMBee
eMBee - avatar
3 Answers
+ 3
You left out the first line. Basically what this function does, is multiplies the numbers together. If you check it with 3 and 11, it will just add 3 11 times together. The same with 7 and 1, it returns 7 times 1
7th Jul 2019, 2:04 PM
Airree
Airree - avatar
+ 2
Airree yeah I did leave out the first line but I've updated the question now
7th Jul 2019, 2:10 PM
eMBee
eMBee - avatar
+ 2
Airree oh, thanks, I never knew that
7th Jul 2019, 2:15 PM
eMBee
eMBee - avatar