Code worked perfectly for me.
Yes, in separate files.
I can only guess that you aren't putting your "funIndex.js" file into the right directory or something like that.
Or maybe you aren't using a web server and are trying to do this all in files???
But even that worked for me, once I allowed the "blocked content".
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.