要点:do{}while() if-else
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script>
var cunqian = 100 ;
var quqian = 0 ;
// var message = prompt('请您输入需要操作的序号:\n1、存钱\n2、取钱\n3、显示余额\n4、退出操作');
do{
var message = prompt('请您输入需要操作的序号:\n1、存钱\n2、取钱\n3、显示余额\n4、退出操作');
if( message == '1'){
cunqian += parseFloat(prompt('请输入存钱的数值'));
alert('此卡的余额还剩'+ (cunqian));
console.log(parseFloat(cunqian))
}else if(message == '2'){
quqian = parseFloat(prompt('请输入取钱的数值'));
console.log(cunqian);
alert('本次取出' + quqian + '元,此卡还剩'+ (cunqian - quqian) );
}else if(message == '3'){
alert('余额还剩'+(cunqian - quqian)+'元');
}
}while(message !== '4');
alert('退出系统')
</script>
</head>
<body>
</body>
</html>
|