title: How to print something in JavaScript from an if/else statement?
body: <p>I wanna add an if/else statement that prints "Only Number are accepted", for older browsers, where they allow you to add a string in a input with <code>type=number</code>.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>  var bttn = document.getElementById("agebttn");
    bttn.addEventListener("click", bttnClicked);
  
    function calculate(startingYear) {
      var dateObj = new Date()
      var currentYear = dateObj.getFullYear()
      return currentYear - startingYear;
    }
  
    function bttnClicked() {
      console.log("bttn clicked");
      var age = parseInt(document.getElementById('age').value);
      var yearsAlive = calculate(age);
  
      var html = "You entered " + age;
      html += "&lt;br /&gt;You have been alive for " + yearsAlive + " years";
      document.getElementById('answer').innerHTML = html;
    }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;body&gt;
    &lt;h1&gt;Age Calculator&lt;/h1&gt;
  
    &lt;input type="number" id="age" placeholder="Enter your birthyear"&gt;
    &lt;input type="button" id="agebttn" value="Calc" /&gt;
    &lt;div id="answer"&gt;
  
    &lt;/div&gt;
  &lt;/body&gt;</code></pre>
  </div>
  </div>
  </p>