Use the plugins I have recommended, and you will easily be able to add JS codes to your WordPress website
Step 1: Log in to your WordPress Dashboard, hover over Plugins, and tap on Add New.
Step 2: Search for Insert Headers and Footers and tap on Install and then Activate. Alternatively, visit this link to download Insert Headers and Footers plugin and upload it on your site.
Step 3: Once the plugin is activated hover over Settings, you will see an option Insert Headers and Footers, tap on it.
Step 4: From the settings page you can enter Scripts in Header, Body, or Footer. Enter the code as you need, scroll down and save the changes.
Next up in my recommendation list are Simple Custom CSS and JS. It is one the best plugin with over 300k active installs to adding External JS Codes in WordPress. Follow along with the steps I have provided to use it.
Step 1: Log in to WordPress Dashboard and head over to Plugins and then tap on Add New.
Step 2: On the Add New Plugins page search for Simple Custom CSS and JS. Tap on Install and once the plugin is installed tap on Activate.
Step 3: As soon as the Plugin will be activated its shortcut will start appearing in the Sidebar, tap on + Custom CSS 7 & JS.
Step 4: On the next screen tap on Add JS Code.
3. WP Coder
Step 1: Search for WP Coder in WordPress Plugin directory, tap on Install Now, and then Activate.
Step 2: Once the plugin has been installed an option named Wow Plugins will appear in the Sidebar. Hover over it and select WP Coder.
Step 3: On the next screen tap on Add New.