Typically, Javascript is not called from the controller (unless it's an AJAX call), but inside a view.
To load an external .js file, you need to use the base_url() function.
E.g., if your js files are in the /assets/js folder, you load it like this (in your view):
Code:
<script src="<?= base_url('assets/js/example.js');?>" />
After this, the functions in your js file are available.
You can save yourself a lot of trouble if you load the jQuery library. It can do a lot of dynamic html actions for you, like showing or hiding parts of your page. It can also simplify AJAX calls.
Good luck.