Adding External JavaScript Files (.js) Into Moodle

You may wonder how to add custom JavaScript files into Moodle. I had the same questin. So, I am writing this article to share how I made it through and ease your process with an example.
Steps

Go inside your “/theme/YourThemeName” folder. If you don’t have “javascript” folder inside “/theme/YourThemeName”, create a new folder called “javascript”.
Inside the new javascript folder that you have created, upload the .js files.
Next, go inside your “/theme/YourThemeName/config.php”. At the very bottom of the file, add a new line of code to include our javascript files.

#To load the js files in your header:
$THEME->javascripts = array(‘yourfirstjsfile’,’yoursecondjsfile’);
#To load the js files in your footer:
$THEME->javascripts_footer = array(‘yourfirstjsfile’,’yoursecondjsfile’);

Link: https://dzone.com/articles/adding-external-javascript-files-js-into-moodle?utm_medium=feed&utm_source=feedpress.me&utm_campaign=Feed%3A+dzone%2Fwebdev