Javascript Tutorial 2 – Making a Basic Calculator




In this tutorial I show you how to make a very basic calculator, this uses many aspects of javascripts, and provides a good starter package of information for any one that is interested in what javascript can do. On that note, this is the absolue basics of what JS can do. Enjoy there is more to come.

Original source


14 responses to “Javascript Tutorial 2 – Making a Basic Calculator”

  1. For those who are having problems a lighter and working script:

    function calc() {
      
    num1 = document.getElementById('num1').value;
    num2 = document.getElementById('num2').value;
    sign = document.getElementById('sign').value;

    if(sign == "*"){

    document.getElementById('result').value = +num1 * +num2;

    }else if(sign == "/"){

    document.getElementById('result').value = +num1 / +num2;

    }else if(sign == "-"){

    document.getElementById('result').value = +num1 – +num2;

    }else{

    document.getElementById('result').value = +num1 + +num2;

    }

    }

Leave a Reply