Home >Web Front-end >JS Tutorial >How to implement multiplication and addition in JavaScript
How to implement multiplication and addition in JavaScript: 1. Create the add and take functions through function and set two parameters; 2. Set the mathematical formulas for addition and multiplication; 3. Enter the parameters and display them in the browser Just output the calculation results in .
The operating environment of this article: windows7 system, javascript version 1.8.5, Dell G3 computer.
How to implement multiplication and addition in JavaScript?
js implementation of addition:
//创建一个add函数,并定义两个参数x,y function add(x,y){ //设置相加的数学公式 return x + y; } //在浏览器中输出计算结果 document.write(add(6,8)+"<br />");
js implementation of multiplication:
//创建一个take函数,并定义两个参数x,y function take(x,y){ /设置相乘的数学公式 return x * y; } //在浏览器中输出计算结果 document.write(take(5,6));
Recommended study: "javascript basic tutorial"
The above is the detailed content of How to implement multiplication and addition in JavaScript. For more information, please follow other related articles on the PHP Chinese website!