猿问

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

<!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>


id路人
浏览 1084回答 1
1回答

摩诃迦叶

if(behavior="save"){amount=amount+number;return amount;} if(behavior="withdraw"){amount=amount-number;return amount;}  behavior="save"这是赋值语句不是比较。  比较是behavior=="save"
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答