Perhaps there is many ways to do it. I will show You my way (tested), so...
In typical WordPress Theme You should have at least files like:
index.php and functions.php (i repeat! -minimal, because it should be much, much more, like also search.php, single.php, and so on, and so on..).
Each of above file should contain html and php code with css for nice frontend, but here i will focus on only the most necessary php and html, so here it is:
contents of index.php
<!DOCTYPE html>
<html <?php language_attributes(); ?>>
<?php get_header(); ?>
<body <?php body_class(); ?>>
<!-- here add Your html and php code of index.php -->
<?php
// Here is the place all magic come true.. get_footer (wp_footer)
// where..
// wp_footer() will call any JAVASCRIPTS code in right way, but
// don't forget inform about it functions.php file in his right section.
// BTW: while wp_footer will call,
// then add_action function will run,
// and will set up correctly all javascript code inside WordPress Core
// (please look into functions.php file)
//
// PLEASE:
// DO NOT ADD ANY JAVASCRIPT CODE HERE (at the end of index file) -
// - it could work, but it is not recommended
//
wp_footer();
?>
</body>
</html>
Now.. Let's say Your Theme is named: Michael_theme
contents of functions.php could looks like for example:
<?php
add_action( 'after_setup_theme', 'Michael_theme_setup' );
function Michael_theme_setup()
{
register_nav_menus( array( 'main-menu' => esc_html__( 'Main Menu', 'Michael_theme' )));
}
// loading HEADER scripts by right WordPress way
add_action( 'wp_enqueue_scripts', 'Michael_theme_enqueue' );
function Michael_theme_enqueue()
{
wp_enqueue_style( 'Michael_theme', get_stylesheet_uri() ); // loading css scripts
wp_enqueue_script( 'jquery' ); // loading jlquery.js (one of js scripts)
// here is another option to add Your own javascript code in js file if You wish
}
// loading FOOTER scripts by WordPress way
add_action( 'wp_footer', 'Michael_theme_footer' );
function Michael_theme_footer()
{
<script>
jQuery(document).ready(function($)
{
alert("test text"); // here is Your text to show
}
</script>
}
if ( !function_exists( 'Michael_theme_wp_body_open' ) )
{
function Michael_theme_wp_body_open() { do_action( 'wp_body_open' ); }
}
?>
You could also cut Your code by divide it by using for example "get_template_part()" WordPress function, and pack the each part into separate php file.
I mean You could call get_template_part inside functions.php file, but.. i am afraid there is not necessary to explain it all here and now. Please ask if You wish.