title: If/else statement and user dropdown selection
body: <p>I have a situation where I need the user to enter either a specific number (their monthly bill for example) or, in the case that they dont have a specific number, to choose from  a dropdown of averages by state. I am unsure how to write an if/else statement that firsts ask if the specific input is defined, and in lieu of a text input, to check for the dropdown value.</p>
  
  <p><strong>Edit: this is my second attempt at getting something workable, no luck :/</strong></p>
  
  <p><strong>JS</strong></p>
  
  <pre><code>    var val = document.getElementById('perKWhCost').value;
      var select_value = document.querySelector('#selection').value;
      var getMonthlyCost = function(){
  
          if (val){
              getMonthlyCost = val;
          }
          else{
              getMonthlyCost = select_value;
          }
          console.log(getMonthlyCost);
      }
  
      var getAnnualSavings = getMonthlyCost * finalAnnualEnergy;
  </code></pre>
  
  <p><strong>HTML</strong></p>
  
  <pre><code>&lt;div class="form-group"&gt;
              &lt;label name="monthlyCost" for="inputKWh"&gt;Per kWh cost(see energy bill)&lt;/label&gt;
              &lt;p&gt;This should look like "&lt;em&gt;$0.11/kWh&lt;/em&gt;"&lt;/p&gt;
              &lt;input type="text" value="" class="form-control" id="perKWhCost" placeholder="0.11"&gt;
              &lt;label for="state"&gt;Or select a state&lt;/label&gt;
              &lt;select name="Cost" id="selection"&gt;
                &lt;option value=".11"&gt;Alabama&lt;/option&gt;
                &lt;option value=".19"&gt;Alaska&lt;/option&gt;
                &lt;option value=".11"&gt;Arizona&lt;/option&gt;
                &lt;option value="AR"&gt;Arkansas&lt;/option&gt;
                &lt;option value="CA"&gt;California&lt;/option&gt;
                &lt;option value="CO"&gt;Colorado&lt;/option&gt;
                &lt;option value=".20"&gt;Connecticut&lt;/option&gt;
                &lt;option value=".13"&gt;Delaware&lt;/option&gt;
                &lt;option value=".13"&gt;District Of Columbia&lt;/option&gt;
                &lt;option value=".12"&gt;Florida&lt;/option&gt;
                &lt;option value=".11"&gt;Georgia&lt;/option&gt;
                &lt;option value="HI"&gt;Hawaii&lt;/option&gt;
                &lt;option value="ID"&gt;Idaho&lt;/option&gt;
                &lt;option value=".11"&gt;Illinois&lt;/option&gt;
                &lt;option value=".11"&gt;Indiana&lt;/option&gt;
                &lt;option value=".11"&gt;Iowa&lt;/option&gt;
                &lt;option value=".12"&gt;Kansas&lt;/option&gt;
                &lt;option value="KY"&gt;Kentucky&lt;/option&gt;
                &lt;option value="LA"&gt;Louisiana&lt;/option&gt;
                &lt;option value=".18"&gt;Maine&lt;/option&gt;
                &lt;option value="MD"&gt;Maryland&lt;/option&gt;
                &lt;option value=".19"&gt;Massachusetts&lt;/option&gt;
                &lt;option value=".15"&gt;Michigan&lt;/option&gt;
                &lt;option value=".12"&gt;Minnesota&lt;/option&gt;
                &lt;option value="MS"&gt;Mississippi&lt;/option&gt;
                &lt;option value=".09"&gt;Missouri&lt;/option&gt;
                &lt;option value="MT"&gt;Montana&lt;/option&gt;
                &lt;option value=".09"&gt;Nebraska&lt;/option&gt;
                &lt;option value="NV"&gt;Nevada&lt;/option&gt;
                &lt;option value="NH"&gt;New Hampshire&lt;/option&gt;
                &lt;option value=".16"&gt;New Jersey&lt;/option&gt;
                &lt;option value="NM"&gt;New Mexico&lt;/option&gt;
                &lt;option value="NY"&gt;New York&lt;/option&gt;
                &lt;option value="NC"&gt;North Carolina&lt;/option&gt;
                &lt;option value=".09"&gt;North Dakota&lt;/option&gt;
                &lt;option value=".12"&gt;Ohio&lt;/option&gt;
                &lt;option value="OK"&gt;Oklahoma&lt;/option&gt;
                &lt;option value="OR"&gt;Oregon&lt;/option&gt;
                &lt;option value=".14"&gt;Pennsylvania&lt;/option&gt;
                &lt;option value=".18"&gt;Rhode Island&lt;/option&gt;
                &lt;option value="SC"&gt;South Carolina&lt;/option&gt;
                &lt;option value=".10"&gt;South Dakota&lt;/option&gt;
                &lt;option value="TN"&gt;Tennessee&lt;/option&gt;
                &lt;option value="TX"&gt;Texas&lt;/option&gt;
                &lt;option value="UT"&gt;Utah&lt;/option&gt;
                &lt;option value=".17"&gt;Vermont&lt;/option&gt;
                &lt;option value="VA"&gt;Virginia&lt;/option&gt;
                &lt;option value="WA"&gt;Washington&lt;/option&gt;
                &lt;option value="WV"&gt;West Virginia&lt;/option&gt;
                &lt;option value="WI"&gt;Wisconsin&lt;/option&gt;
                &lt;option value="WY"&gt;Wyoming&lt;/option&gt;
              &lt;/select&gt;
            &lt;/div&gt;
  
  
            &lt;input type="button" value="Calculate!" id="submit" class="btn btn-default btn-lg" onclick="doMath();"&gt;
          &lt;/form&gt;
  </code></pre>
  
  <p><strong><em>Note: the JS above is part of the function doMath which is not fully shown here. Additionally, ignore that not every selection has a decimal value yet, that will be changed in the working code.</em></strong></p>
  
  <p>This is the gist of what I need. I need to check if there is a value in the text field, if there is I want getMonthlyCost to store that value (preferably only if its a number). If there is no input in the text box I want the code to check the selector dropdown and take the users selection and pass that value to getMonthlyCost. </p>