Javascript does not work when signed in or when comments are open
To get the jquery alias $ working in drupal, you have map it like this:

(function ($) {
  $(document).ready(function() {
    alert("Here I am");   
  });
})(jQuery);


The document ready function is not the best option, better use Drupal.behaviors and once():

https://www.drupal.org/docs/8/api/javascript-api/javascript-api-overview