Index.html error about scripts, but I have to have a script load after the body for my code to work?!

I’m trying to build my first Component (a nav bar). I have custom html/css for a hamburger menu and a shopping cart and then the site logo in the middle.

In order for the menu and shopping cart to work I created some js which is saved in it’s own file.

However, in order for this code to work, I must place the script load line after the closing body html tag:

    </body>

    <script src="assets/js/aiboetc.js"></script>     

</html>

but when I do this and next reload the project I get an error warning.

The warning goes away if I put the script load in the head tag, but then my code doesn’t work.

Could someone please tell me where I’ve gone wrong?

Thanks.

Sorry, I think I’ve fixed it: How To Defer JavaScript On Your Website | DebugBear.

Needed to add ‘defer’ to the end of the script line when in the ‘head’ section.