Hi Frank,
I also had that the same issue as you while implementing the proposed solution, I solved it by following the advice about putting the code in a new file called custom.json and Assests and adding the following in theme.liquid just before the tag :
{{ ‘custom.js’ | asset_url | script_tag }}
I hope it helps,
Mike