title: Javascript binding switch's case to a html button
body: <p>I've been trying to make a button that would invoke a JavaScript case from switch. The script I tried to create was supposed to calculate square's perimeter and area but it doesn't seem to work.</p>
  
  <pre><code>&lt;html&gt;
  &lt;body&gt;
  &lt;form&gt;
  &lt;input type=text id="num"&gt;&lt;br&gt;
  &lt;input type="button" value="area" id="abut" onclick=" return calc(this.value)"&gt;
  &lt;input type="button" value="per" id="pbut" onclick=" return calc(this.value)"&gt;
  &lt;/form&gt;
  &lt;script&gt;
  function calc(count) {
      var a =parseInt(document.getElementById("num").value);
      var w;
      if isNaN(a) {
          alert("Input a number");
      }
      else {
          switch(count) {
              case 'area' :
                  w=a*a;
                  break;
              case 'per' :
                  w=a*4;
                  break;
          }
          document.getElementById("res").innerHTML = w;
      }
  }
  &lt;/script&gt;
  &lt;p id="res"&gt;&lt;/p&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>