There are several ways to add JavaScript snippets to your site. They can be embedded into an existing html page, added to an existing .js file, or added as separate files which are called when the HTML page loads.

Adding JS as a separate, external file

In this method, you upload the JavaScript to your site as a individual file, and add a PHP code snippet to a .php file. (When a visitor views the page, this PHP snippet creates HTML code which makes their browser load the .js file). The PHP snippet will look something like this:

drupal_add_js('path-to/javascript.js', 'theme');

This method is often used to load .js files by adding that PHP snippet to the end of template.php in your site's theme directory.

See also: How can I add a Javascript? http://drupal.org/node/333056

Troubleshooting JavaScript Snippets

In FireFox, use Tools > Web Developer > Browser Console (or Ctrl + Shift + J). Clear the error console and then look at it when you load the page. For example, it will let you know if an external .js file didn't load because you got the path wrong. Note: some errors can be safely ignored.