Selenium Testing $ not defined while loading jQuery

public static void runTimeInfo(String messageType, String message) throws InterruptedException {
    js = (JavascriptExecutor) driver;

    // Check for jQuery on the page, add it if need be
    js.executeScript("if (!window.jQuery) {"
            + "var jquery = document.createElement('script'); jquery.type = 'text/javascript';"
            + "jquery.src = 'https://code.jquery.com/jquery-3.6.4.min.js';"
            + "document.getElementsByTagName('head')[0].appendChild(jquery);" 
            + "}");

    // Wait for jQuery to load
    js.executeScript("var waitForJQuery = setInterval(function() {"
            + "if (window.jQuery) {"
            + "clearInterval(waitForJQuery);"
            + "jQuery.noConflict();"
            + "}" 
            + "}, 100);");

    // Use jQuery to add jquery-growl to the page
    js.executeScript("jQuery.getScript('https://the-internet.herokuapp.com/js/vendor/jquery.growl.js')");

    // Use jQuery to add jquery-growl styles to the page
    js.executeScript("jQuery('head').append('<link rel="stylesheet" "
            + "href="https://the-internet.herokuapp.com/css/jquery.growl.css" " 
            + "type="text/css" />');");

    // jquery-growl w/ no frills
    js.executeScript("jQuery.growl({ title: 'GET', message: '/' });");

    if (messageType.equals("error")) {
        js.executeScript("jQuery.growl.error({ title: 'ERROR', message: '"+message+"' });");
    } else if (messageType.equals("info")) {
        js.executeScript("jQuery.growl.notice({ title: 'Notice', message: 'your notice message goes here' });");
    } else if (messageType.equals("warning")) {
        js.executeScript("jQuery.growl.warning({ title: 'Warning!', message: 'your warning message goes here' });");
    } else {
        System.out.println("no error message");
    }

    // jquery-growl w/ colorized output
    //js.executeScript("jQuery.growl.error({ title: 'ERROR', message: 'your error message goes here' });");
    //js.executeScript("jQuery.growl.notice({ title: 'Notice', message: 'your notice message goes here' });");
    //js.executeScript("jQuery.growl.warning({ title: 'Warning!', message: 'your warning message goes here' });");

    Thread.sleep(5000);
}

this code is giving me $ not defined error. can anyone help with the solution?? I am using firefox for the testing. please let me know if you needed any additional information as I am new to selenium I am not sure how to resolve it. I have tried changing jQuery versions, but it is still not working.