使用 JavaScript 根据消费金额和消费者是否为会员确定折扣,最终核算实际应该支付的金额

查看本章节

查看作业目录


需求说明:

根据消费金额和消费者是否为会员确定折扣,最终核算实际应该支付的金额

  • 消费金额在 200 元以上的会员折扣是 7.5 折,消费金额没有达到 200 元的会员折扣是 9 折
  • 非会员只有消费金额在 100 元以上才有 9 折优惠

实现思路:

  1. 创建站点,新建HTML页面,在页面中嵌入 <script></script> 脚本标签
  2. 定义变量分别用于保存身份和消费的金额
  3. 用 if 语句判断身份和消费的金额,计算出各个情况下的实际消费金额 使用浏览器预览效果

实现代码:

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<script type="text/javascript">
			var identity = true;
			var money = 340;
			if (identity) {//会员
				if (money>200) {
					money = money * 0.75;
				} else{
					money = money * 0.9;
				}
			} else{
				if(money >100){//非会员
					money = money * 0.9;
				}
			}
			document.write("非会员消费340,实际支付"+money);
		</script>
	</body>
</html>

 

  • 2
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
好的,我可以回答这个问题。以下是将数字金额转换为中文大写金额JavaScript代码: ```javascript function convertToChineseNumeral(amount) { const chineseNumeral = ["零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"]; const chineseUnit = ["", "拾", "佰", "仟"]; const chineseBigUnit = ["", "萬", "亿", "兆"]; let num = parseFloat(amount); let chineseAmount = ""; if (isNaN(num)) { return ""; } let isNegative = num < 0; if (isNegative) { num = -num; } let fraction = Math.round((num - Math.floor(num)) * 100); if (fraction == 0) { chineseAmount += "整"; } else { chineseAmount += chineseNumeral[Math.floor(fraction / 10)] + "角"; chineseAmount += chineseNumeral[fraction % 10] + "分"; } num = Math.floor(num); let unitIndex = 0; while (num > 0) { let currentUnit = ""; for (let i = 0; i < 4 && num > 0; i++) { let currentNumeral = num % 10; if (currentNumeral > 0) { currentUnit = chineseUnit[i] + currentUnit; currentUnit = chineseNumeral[currentNumeral] + currentUnit; } else if (currentUnit != "") { currentUnit = chineseNumeral[currentNumeral] + currentUnit; } num = Math.floor(num / 10); } if (currentUnit != "") { currentUnit += chineseBigUnit[unitIndex]; } chineseAmount = currentUnit + chineseAmount; unitIndex++; } if (chineseAmount == "") { chineseAmount = chineseNumeral[0]; } if (isNegative) { chineseAmount = "负" + chineseAmount; } return chineseAmount; } console.log(convertToChineseNumeral(123456789.01)); // 壹亿贰仟叁佰肆拾伍萬陆仟柒佰捌拾玖元零壹分 ``` 希望这个代码能帮到你。如果你有其它问题,欢迎继续询问。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

明金同学

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值