目录
练习-04 用户购买商品,三个商品中有一个超过50元,或者总价超过100元,即可以打八五折,否则不打折,输出最终商品价格**
练习-05 编辑四则运算计算器:两个数的加减乘除四则运算**
练习-06 工资所得税工资超过1000的部分需要缴纳个人所得税(税率0.05),根据用户输入的工资,输出税后工资**
练习-01 输入一个数来判断奇数和偶数**
<script>
// 01. 判断一个数是否为偶数
var num1 = Number(prompt("请输入一个数字"));
if (num1 % 2 == 0) {
console.log(num1 + " 这是一个偶数");
} else {
console.log(num1 + " 这是一个奇数");
}
</script>
练习-02 输入一个三位正整数来判断水仙花数**
水仙花数是指一个 3 位数,它的每个位上的数字的 3次幂之和等于它本身。(例如:1^3 + 5^3+ 3^3 = 153)
// 02*输入一个三位正整数来判断水仙花数**
// 水仙花数是指一个 3 位数,它的每个位上的数字的 3次幂之和等于它本身。(例如:1^3 + 5^3+ 3^3 = 153)
var num = Number(prompt("请输入一个三位数字"));
var bai = parseInt(num / 100);
var shi = parseInt(num / 10) % 10;
var ge = num % 10;
if (bai * bai * bai + shi * shi * shi + ge * ge * ge == num) {
console.log(num + "是回文数");
} else {
console.log(num + "不是水仙花数");
}
练习-03 判断输入年份是不是闰年**
(普通闰年:公历年份是4的倍数,且不是100的倍数的,为闰年(如2004年、2020年等就是闰年)。
世纪闰年:公历年份是整百数的,必须是400的倍数才是闰年(如1900年不是闰年,2000年是闰年)。)
var year = Number(prompt("请输入一个年份"));
if (year % 4 == 0 && year % 100 != 0) {
console.log(year + "是闰年");
}else if (year % 100 == 0 && year % 400 == 0) {
console.log(year + "是世纪闰年");
}else {
console.log(year + "不是闰年");
}
练习-04 用户购买商品,三个商品中有一个超过50元,或者总价超过100元,即可以打八五折,否则不打折,输出最终商品价格**
var a = Number(prompt("请输入商品1的价格:"));
var b = Number(prompt("请输入商品2的价格:"));
var c = Number(prompt("请输入商品3的价格:"));
var num = Number;
if (a > 50 || b > 50 || c > 50) {
num = a * 0.85 + b * 0.85 + c * 0.85;
console.log("打85折" + "最终价格为:" + num + "元");
} else if (a + b + c > 100) {
num = a * 0.85 + b * 0.85 + c * 0.85;
console.log("打85折" + "最终价格为:" + num + "元");
} else {
num = a + b + c;
console.log("不打85折" + "最终价格为:" + num + "元");
}
练习-05 编辑四则运算计算器:两个数的加减乘除四则运算**
从窗口分别输入第一个数,第二个数,以及运算符的符号进行四则运算,并弹出运算结果
var num1 = Number(prompt("请输入第一个数"));
var str = prompt("请输入一个运算符");
var num2 = Number(prompt("请输入第二个数"));
if (str == "+") {
alert(num1 + '+' + num2 + '=' + (num1 + num2));
}
if (str == "-") {
alert(num1 + '-' + num2 + '=' + (num1 - num2));
}
if (str == "*") {
alert(num1 + '*' + num2 + '=' + (num1 * num2));
}
if (str == "/") {
alert(num1 + '/' + num2 + '=' + (num1 / num2));
}
练习-06 工资所得税工资超过1000的部分需要缴纳个人所得税(税率0.05),根据用户输入的工资,输出税后工资**
// 06 // 工资所得税 工资超过1000的部分需要缴纳个人所得税(税率0.05),
// 根据用户输入的工资,输出税后工资
var num6 = Number(prompt("请输入工资"));
if (num6 > 1000) {
alert(num6 - (num6 - 1000) * 0.05);
} else {
alert("哇!!!你工资不够吗?");
}