当前位置:网站首页>JS function to realize simple calculator
JS function to realize simple calculator
2022-06-25 05:02:00 【Dai Sensen】
var n = prompt(' Welcome to the easy calculator :\n1. Addition calculator :\n2. Subtraction calculator :\n3. Multiplication calculator :\n4 Division calculator :\n5. sign out :\n Please enter your choice :');
function Calculate(n) {
n = parseInt(n);
while (n != 5) {
switch (n) {
case 1:
n1 = parseInt(prompt(' Please enter the first number '));
n2 = parseInt(prompt(' Please enter the second number '));
alert(n1 + n2);
break;
case 2:
n1 = parseInt(prompt(' Please enter the first number '));
n2 = parseInt(prompt(' Please enter the second number '));
alert(n1 - n2);
break;
case 3:
n1 = parseInt(prompt(' Please enter the first number '));
n2 = parseInt(prompt(' Please enter the second number '));
alert(n1 * n2);
break;
case 4:
n1 = parseInt(prompt(' Please enter the first number '));
n2 = parseInt(prompt(' Please enter the second number '));
alert(n1 / n2);
break;
case 5:
n = 5;
break;
}
n = prompt(' Welcome to the easy calculator :\n1. Addition calculator :\n2. Subtraction calculator :\n3. Multiplication calculator :\n4 Division calculator :\n5. sign out :\n Please enter your choice :');
n = parseInt(n);
}
}
Calculate(n);
边栏推荐
- Database overview
- 固態硬盤開盤數據恢複的方法
- Construction scheme of distributed websocket
- 成功解决:selenium.common.exceptions.TimeoutException: Message: timeout: Timed out receiving message from
- SOC验证环境的启动方式
- Database query optimization method
- 【Keil】ADuCM4050官方库的GPIO输出宏定义
- Virtual honeypot Honeyd installation and deployment
- Difference between asemi high power FET and triode
- 执行SQL响应比较慢,你有哪些排查思路?
猜你喜欢
随机推荐
Kotlin Compose 监听软键盘 点击enter提交事件
ORA-00800: soft external error
What if the desktop computer is not connected to WiFi
小白一键重装官网下载使用方法
How micro engine uploads remote attachments
MySQL prevents Chinese garbled code and solves the problem of Chinese garbled code
Codeforces Round #802 (Div. 2) C D
Qdebug June 2022
【FLink】access closed classloader classloader. check-leaked-classloader
Sleep more, you can lose weight. According to the latest research from the University of Chicago, sleeping more than 1 hour a day is equivalent to eating less than one fried chicken leg
Student achievement management system based on SSH
How PHP gets the user's City
SRC platform summary
API interface management setup -eolinker4.0
Working principle of asemi three-phase rectifier bridge
Detailed summary of position positioning
CTFHub-rce
Wechat applet new version prompt update
台式电脑连不上wifi怎么办
Filter & listener (XIV)