<script type="text/javascript">
var isBuy = "y";
do{
var vendingMachine = prompt("请问要买什么饮料:");
switch (vendingMachine) {
case "1":
alert("你选择的1号饮料:" + "可乐");
break;
case "2":
alert("你选择的2号饮料:" + "雪碧");
break;
case "3":
alert("你选择的3号饮料:" + "绿茶 ");
break;
case "4":
alert("你选择的4号饮料:" + "脉动");
break;
case "5":
alert("你选择的5号饮料:" + "雀巢咖啡");
break;
default:
alert("没有该商品");
break;
}
isBuy = prompt("是否继续购买饮料y/n:");
}while(isBuy == "y");
</script>
js 模拟自动饮料机,当输入1-5中的任意整数,则给出对应的饮料。并提示是否继续购买饮料。
最新推荐文章于 2022-12-28 22:16:33 发布