We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
功能基本实现,但还存在以下bug:
Infinity
此外,功能以外的方面再提几点建议:
The text was updated successfully, but these errors were encountered:
我是没有考虑先输入%或者=的情况,这一点我再改进! infinity后可以继续加减乘除得到的都还是infinity这个不行吗? 代码命名有问题,我会再进一步改进。代码重构会跟进! 谢谢寿寿学长指导
Sorry, something went wrong.
infinity是一个类似error的情况,现实的计算器的处理方式是必须按AC来清空才可以继续输入,你参照windows自带计算器的处理方式
好的!
#20 JS代码重构得不错,懂得抽象出numberClick和symbolClick函数就算达到了了解重构的目的。请以后在写代码的时候随时随地保持重构代码的思考。当然,press函数还可以再精简,设想我现在要你再添加“sin”“log”等等10几个按钮来做一个科学计算器,那你岂不是每添加一个按钮,就得在HTML中添加onclick="press('sin')",例如下面这样:
numberClick
symbolClick
press
onclick="press('sin')"
function press() { buttonId = document.getElementById("result"); //定义符号表 var SYMBOL_LIST = ['+', '-', 'x', '/', '%']; //用内置的event.target来获取点击的按钮内容 var value = event.target.innerHTML; console.log(value); //处理数字 if(value >= '0' && value <= '9') { numberClick(value); } else if (SYMBOL_LIST.indexOf(value) > -1) { //处理符号 symbolClick(value); } else { //处理其他 switch(value) { case 'AC': //...... } } //......
当然还有更高级代码健壮性更强的重构方法,用到Javascript的function对象来处理不同的功能,这里就不再展开了。
任务3完成
lidasong
No branches or pull requests
功能基本实现,但还存在以下bug:
Infinity
(这个结果是对的),但是后面还可以继续输入,输入内容就接在了Infinity后面此外,功能以外的方面再提几点建议:
The text was updated successfully, but these errors were encountered: