为了账号安全,请及时绑定邮箱和手机立即绑定

这个代码哪里错了,为什么不能减?

这个代码哪里错了,为什么不能减?

id路人 2016-09-12 22:11:51
<!doctype html><html><head><meta charset="utf-8"><title>JS语法练习3</title><script> var amount = 0; function bankSystem(behavior,number){ if(behavior="save"){amount=amount+number;return amount;} if(behavior="withdraw"){amount=amount-number;return amount;} } function checkAmount(){ document.write(amount+"<br>"); } bankSystem("save",1000); checkAmount(); bankSystem("withdraw",300); checkAmount(); bankSystem("withdraw",850); checkAmount(); bankSystem("save",700); checkAmount(); bankSystem("withdraw",60); checkAmount(); bankSystem("save",100); bankSystem("save",200); bankSystem("withdraw",1000); bankSystem("save",500); bankSystem("withdraw",200); checkAmount(); </script></head><body></body></html>
查看完整描述

1 回答

已采纳
?
摩诃迦叶

TA贡献146条经验 获得超54个赞


if(behavior="save"){amount=amount+number;return amount;}

if(behavior="withdraw"){amount=amount-number;return amount;} 

behavior="save"这是赋值语句不是比较。  比较是behavior=="save"


查看完整回答
1 反对 回复 2016-09-12
  • 1 回答
  • 0 关注
  • 1082 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信