title: Why won't my JavaScript calculations involving if statements work?
body: <p>The idea is to generate a random number from 1 to 10, which will be the amount of pounds of product ordered. Then, using that number, the code will calculate the cost of the product and the cost of the shipping, adding them together to create a total. It will then write information about the purchase to the HTML document.</p>
  
  <p>The problem is not the random number generator; that's working fine. It also doesn't appear to be the final step of writing information to the document. Rather, it seems that my calculations, enclosed in if-else statements, are not working. JavaScript is reading <code>costBox</code>, <code>costShipping</code>, and <code>costTotal</code> as undefined. I have tried changing around the syntax, and I've gone over the code to ensure that there are no missing parentheses or brackets. I've consulted my textbook, but the code is laid out similarly there. Can you help me figure out what's wrong?</p>
  
  <p>Here is my code:</p>
  
  <pre><code>var num = Math.ceil(Math.random() * 10);
         var costBox;
         var costShipping;
         var costTotal;
  
         if (num &gt;= 1 &amp;&amp; num &lt;= 5) {
          costBox == 20;
         }
         else if (num &gt;= 6 &amp;&amp; num &lt;= 9) {
          costBox == 15;
         }
         else if (num == 10) {
          costBox == 10;
         }
  
         if (num &gt;= 1 &amp;&amp; num &lt;= 3) {
          costShipping == 5;
         }
         else if (num &gt;= 4 &amp;&amp; num &lt;= 7) {
          costShipping == 10;
         }
         else if (num == 8 || num == 9) {
          costShipping == 15;
         }
         else if (num == 10) {
          costShipping == 20;
         }
  
         costBox == costBox * num;
         costTotal == costBox + costShipping; 
  
         window.onload = function() {
          document.getElementById("pageNum").innerHTML = num;
          document.getElementById("pageBox").innerHTML = costBox.toFixed(2);
          document.getElementById("pageShipping").innerHTML = costShipping.toFixed(2);
          document.getElementById("pageTotal").innerHTML = costTotal.toFixed(2);
         }
  </code></pre>
  
  <p>Here is the code after NPE's recommendations:</p>
  
  <pre><code>       var num = Math.ceil(Math.random() * 10);
         var costBox;
         var costShipping;
         var costTotal;
  
         if (num &gt;= 1 &amp;&amp; num &lt;= 5) {
          costBox = 20;
         }
         else if (num &gt;= 6 &amp;&amp; num &lt;= 9) {
          costBox = 15;
         }
         else if (num == 10) {
          costBox = 10;
         }
  
         if (num &gt;= 1 &amp;&amp; num &lt;= 3) {
          costShipping = 5;
         }
         else if (num &gt;= 4 &amp;&amp; num &lt;= 7) {
          costShipping = 10;
         }
         else if (num = 8 || num = 9) {
          costShipping = 15;
         }
         else if (num = 10) {
          costShipping = 20;
         }
  
         costBox == costBox * num;
         costTotal == costBox + costShipping; 
  
  
         window.onload = function() {
          document.getElementById("pageNum").innerHTML = num;
          document.getElementById("pageBox").innerHTML = costBox.toFixed(2);
          document.getElementById("pageShipping").innerHTML = costShipping.toFixed(2);
          document.getElementById("pageTotal").innerHTML = costTotal.toFixed(2);
         }
  </code></pre>