This article shares the specific code of JavaScript to implement the minesweeper game of the web calculator for your reference. The specific content is as follows First look at the effect: In addition, the calculator also comes with digital and operator checking functions: Paste the source code below: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Calculator</title> <script language="javascript"> var oper1=prompt("Please enter the first operand:"); var oper2 = prompt("Please enter the second operand: "); var operator=prompt("Please enter the operator (+, -, *, /)"); parse(); var result; switch(operator) { case"+": result=doSum(oper1,oper2); alert(oper1+"+"+oper2+"="+result); break; case"-": result = doSubstract (oper1, oper2); alert(oper1+"-"+oper2+"="+result); break; case"*": result = doMultiply(oper1,oper2); alert(oper1+"*"+oper2+"="+result); break; case"/": result = doDivide(oper1,oper2); alert(oper1+"/"+oper2+"="+result); break; default: alert("The operator entered is illegal"); } function parse(){ if(isNaN(oper1)||isNaN(oper2)){ alert("The number entered is illegal"); } else{ oper1 = parseFloat(oper1); oper2 = parseFloat(oper2); } } function doSum(oper1,oper2){ return oper1+oper2; } function doSubstract(oper1,oper2){ return oper1-oper2; } function doMultiply(oper1,oper2){ return oper1*oper2; } function doDivide(oper1,oper2){ return oper1/oper2; } </script> </head> <body> </body> </html> Of course, only the JavaScript source code is shown here. You can also use html+css to design a nice appearance for the calculator. You can feel free to use it. The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: Detailed explanation of common MySQL operation commands in Linux terminal
>>: Complete steps for mounting a new data disk in CentOS7
This article shares the specific code of JavaScri...
Copy code The code is as follows: <style type=...
Table of contents Overview 1. How to animate a DO...
1. First, double-click the vmware icon on the com...
01. VMware Workstation Pro 15 Download Download: ...
Native js realizes the carousel effect (seamless ...
Table of contents 1. Encapsulate complex page dat...
I searched the entire web and found all kinds of ...
1. View the detailed information of all current c...
Make an animation of the eight planets in the sol...
Preface In MySQL, cross-database queries are main...
Basics 1. Use scaffolding to create a project and...
echarts component official website address: https...
Table of contents 1. Bootstrap Grid Layout 2. Ver...
background Today, I was browsing CodePen and saw ...