How do I add javascript to a node or block I've made a cost calculator script and want to use it on my Drupal 7 site. 

I heard to use drupal_add_js, but I don't know in what context.
Use a function in the template.php file: yoursite.com/sites/all/themes/YOUR_THEME/template.php

Add JS file in a block: 

function YOUR_THEME_preprocess_block(&amp;$variables) {  
    drupal_add_js(drupal_get_path('theme', 'MYTHEME') .'/scripts/path');
} 


Add JS file to one page or node:

function YOUR_THEME_preprocess_page(&amp;$variables) {
  if ($variables['nid'] == 'INSERT_NODE_ID') {
     drupal_add_js(drupal_get_path('theme', 'MYTHEME') .'/scripts/path');
  }
}


Add JS file to a content type:

function YOUR_THEME_preprocess_node(&amp;$variables) {
  if ($variables['type'] == 'INSERT_CONTENT_TYPE') {
       drupal_add_js(drupal_get_path('theme', 'MYTHEME') . '/scripts/path');
  }
}


Add JS file to a view:

function YOUR_THEME_preprocess_views_view(&amp;$variables){
  if ($variables['name'] == 'INSERT_VIEW_MACHINE_NAME') {
    // include javascript
    drupal_add_js(drupal_get_path('theme', 'MYTHEME') . '/scripts/path');
  }
}


As mentioned by @Pierpaolo Cira, you could always replace MY_THEME with MY_MOUDLE. To get the path to your module you would have to use drupal_get_path('module', 'my_module').

Note: MY_THEME and MY_MODULE needs to be lowered case if your module or theme name is lowercased. (E.g. MY_THEME would be replaced with zen if zen)

Source