<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
var a = parseInt(prompt("请输入消费金额:"))
if (a >= 50) {
var b = parseInt(prompt("是否参加换购活动请选择:\n1:满50元,加2元换购百事可乐饮料一瓶。\n2:满100元,加3元换购500ml可乐一瓶\n3:满100元,加10元换购5斤面粉。\n4:满200元,加10元换购一个苏泊尔炒菜锅。\n5:满200元,加20元换购欧莱雅爽肤水一瓶。\n0:不换购。"))
switch (b) {
case 1:
document.write("本次消费总金额:" + (a + 2) + "<br>" + "成功:换购百事可乐饮料一瓶。");
break;
break;
}
if (a >= 100 && a < 200) {
switch (b) {
case 2:
document.write("本次消费总金额:" + (a + 3) + "<br>" + "成功换购:500ml可乐一瓶")
break;
case3:
document.write("本次消费总金额:" + (a + 10) + "<br>" + "成功换购:5斤面粉。")
break;
case 0:
document.write("不换购");
break;
default:
document.write("不满足换购条件");
}
}
else {
switch (b) {
case 4:
document.write("本次消费总金额:" + (a + 10) + "<br>" + "成功:换购一个苏泊尔炒菜锅。")
break;
case 5:
document.write("本次消费总金额:" + (a + 20) + "<br>" + "成功:换购欧莱雅爽肤水一瓶。")
break;
case 0:
document.write("不换购");
break;
default:
document.write("不满足换购条件");
}
}
}
else {
document.write("输入本次消费金额" + a)
}
</script>
</body>
</html>
效果