1、输入一员工工资,要求计算税后工资。计算规则如下(
(1)若3000元以下不交税;若3000-5999元交税基数为工资的1%,计算税方式为(税前工资-3000)*0.01;
(2)若6000-9999元高于6000的那部分交税基数为工资的2%,计算税的方式为3000*0.01+(税前工资-6000)*0.02);
(3)若10000元以上3000-6000元交1%;6000-10000交2%;剩余部分交3%。即计算税的方式为3000*0.01+4000*0.02+(税前工资-10000)*0.03.
请利用prompt输入员工工资,利用document.write输出税后工资。
(1)若3000元以下不交税;若3000-5999元交税基数为工资的1%,计算税方式为(税前工资-3000)*0.01;
(2)若6000-9999元高于6000的那部分交税基数为工资的2%,计算税的方式为3000*0.01+(税前工资-6000)*0.02);
(3)若10000元以上3000-6000元交1%;6000-10000交2%;剩余部分交3%。即计算税的方式为3000*0.01+4000*0.02+(税前工资-10000)*0.03.
请利用prompt输入员工工资,利用document.write输出税后工资。
{
var jg=prompt("请输入税前工资","")
if (jg<=3000)
{
document.write("税后工资为"+jg);
}else if(3000<jg&&jg<=5999){
jg=jg-(jg-3000)*0.01;
document.write("税后工资为"+jg);
}else if(6000<=jg&&jg<=9999){
jg=jg-3000*0.01-(jg-6000)*0.02;
document.write("税后工资为"+jg);
}
else if(10000<=jg){
jg=jg-3000*0.01-4000*0.02-(jg-10000)*0.03;
document.write("税后工资为"+jg);
}
} 调用 disp_prompt()这个方法就可以了
刚好在练习&&和||运算符,哈哈
var t = {
money: 0,
init: function() { ((this.money = prompt('输入你的税前工资'), (/^\d*$/.test(this.money) && this.money != 0)) && (this.money = parseInt(this.money), this.getResult(this.money))) || (alert('请输入数字'), (confirm('重新输入?') && this.init())); },
getResult: function(m) {
var $m = this.money;
((m >= 3000 && m <= 5999) && ($m -= (m - 3000) * 0.01)) || ((m >= 6000 && m <= 9000) && ($m -= 3000 * 0.01 + (m - 6000) * 0.02)) || ((m >= 10000) && ($m -= 3000 * 0.01 + 4000 * 0.02 + (m - 10000) * 0.03))
document.write('税后工资:' + $m);
return $m;
} }
t.init();
全JS写的