title: TypeError: null reference error
body: <p>I'm learning codeacademy javascript codes and I really not understand why it gives me this error:</p>
  
  <blockquote>
    <p>TypeError: Unable to get property 'magazine' of undefined or null reference</p>
  </blockquote>
  
  <ol>
  <li>Write the add method which has a single parameter, itemCost. It will add the itemCost to the total.</li>
  <li>We have partially written the scan method for you and started a switch statement. Add the following 2 items to the switch statement:  
  
  <ul>
  <li>"magazine", 4.99  </li>
  <li>"chocolate", 0.45</li>
  </ul></li>
  </ol>
  
  <p>Finally, use the scan method to buy 2 eggs and 3 magazines. </p>
  
  <pre><code>var cashRegister = {
      total: 0,
  
      add: function(itemCost) {
          itemCost += total
      },
  
      scan: function(item) {
          switch (item) {
              case "eggs":
                  this.add(0.98);
                  break;
  
              case "milk":
                  this.add(1.23);
                  break;
  
                  //Add other 2 items here
              case 'magazine':
                  this.add(4.99);
                  break;
              case 'chocolate':
                  this.add(0.45);
                  break;
          }
          return true;
      }
  };
  
  
  cashRegister.sacan['eggs', 'eggs', 'magazine', 'magazine']
  
  console.log('Your bill is ' + cashRegister.total);
  </code></pre>