Can you help me with JavaScript function scopes? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Can you help me with JavaScript function scopes?

Hello. I am making a complex program. It's almost done, but I hit a problem. I need to call a function that is defined in different scope. I won't share the whole code here, because it has about 800 lines and looks very ugly, but I will post simplified version where functions only print a letter. How can I make thos work? https://code.sololearn.com/WMmed3NCepGK/?ref=app

9th Aug 2018, 6:20 PM
Jan Štěch
Jan Štěch - avatar
3 Answers
+ 1
Did you mean to write `smallFunc1` on line 19?
9th Aug 2018, 6:29 PM
Schindlabua
Schindlabua - avatar
+ 1
Sousou Schindlabua Damn! This is what happens when you try to write code while watching TV. Thanks for your answers, but I think that in my complex version is error in something else then wrong function name. I will write here again if it still don't work.
9th Aug 2018, 7:35 PM
Jan Štěch
Jan Štěch - avatar
0
//fixed var i = 0; window.onload = function(){ document.write("A"); smallFunc1(); function smallFunc1(){ document.write("B"); i++ bigFunc(); return; } function bigFunc(){ document.write("C"); if(i<3){smallFunc1();} return; } }
9th Aug 2018, 7:27 PM
Sousou
Sousou - avatar