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”
Great video, very informative. I had a simple question: How do you set the number of decimal places displayed? Thanks in advance.
The syntax I was looking for without all of the fluff. Nice.
can you help me out we need a website that enable you to order and calculat??
Once created the app, how to upload it as build-in function to my website ?
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;
}
}
got it to work forgot the doCalc(); at the end
It is not working for me.
I met the same problem. could u tell me the solution?
This helped me with my finals 😀 thanks a lot!!
nevermind i foun the solution 😀
Hey man im getting an error when i calculate it says in the console that calc is not defined please help me man 😀
u should use html entities for the ×÷ signs
Followed your instructions step by step and it works! thanks for posting this!
wheres part 1