Use JavaScript to write simple calculator _ javascript tips-js tutorial

Source: Internet
Author: User
This article mainly introduces how to use JavaScript to compile a simple calculator. If you need a simple calculator, you can refer to the method described in this article. The idea is very recommendable.

The Code is as follows:






Simple javascript Calculator
Script
// Define the global variable var one = "1 ";
Var two = "2 ";
Var three = "3 ";
Var four = "4 ";
Var five = "5 ";
Var six = "6 ";
Var seven = "7 ";
Var eight = "8 ";
Var nine = "9 ";
Var zero = "0 ";
Var plus = "+", minus = "-", multiply = "*", pide = "/", decimal = ".";
Function enter (obj, string ){
Obj. expr. value + = string;
}
Function compute (obj) {// click the function that is called by the = "=" button; obj. expr. value = eval (obj. expr. value); // use the eval () method of JS to calculate the formula in the name as expr}
Script





Is it super NB code!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.