计算年终奖
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>计算年终奖</title>
</head>
<body>
工龄:<input type="text" value="1" id="workYear">
<br>
薪资:<input type="text" value="14000" id="workMoney">
<br>
<button id="submit">计算年终奖</button>
<br>
你的年终奖是:¥ <span id="valBox"></span>
<!-- IMPORT JS -->
<script>
let workYear = document.getElementById('workYear');
let workMoney = document.getElementById('workMoney');
let submit = document.getElementById('submit');
let valBox = document.getElementById('valBox');
submit.onclick = function () {
// 1.获取文本框中的信息
// 文本框.value 获取输入的内容,格式是字符串
let year = Number(workYear.value);
let money = Number(workMoney.value);
if (isNaN(year) || isNaN(money)) {
alert('输入的内容是非法格式~~');
return;
}
// 2.经过逻辑处理,计算出结果
let result = null;
if (year < 1) {
result = money >= 8000 ? money * 1.2 : money;
} else if (year >= 1 && year < 2) {
result = money >= 10000 ? money * 1.7 : money * 1.5;
} else {
result = money >= 12000 ? money * 3.2 : money * 3;
}
// 3. 把结果赋值给 #valBox 即可
valBox.innerHTML = result;
}
</script>
</body>
</html>