我的名为myEmployees的数组中有5个名字,但是当我运行代码时,它只打印出其中的3个.我相信这种情况正在发生,因为脚本中的for循环覆盖了它在
HTML文档中编写的前一行.我怎样才能解决这个问题?
Yearly Bulletin Board Announcements!
Congratulations to Taylor, you have been here for 9 years and you meet the magic number! You get 2 extra weeks of PTO!
Derek, thank you for your service over the past 8 years. I look forward to many more years working with you!
Tyler, no longer works here.
以上是我运行代码时在屏幕上显示的内容,应该有另外两个语句出现.任何建议将不胜感激!
Yearly Buttetin Board Announcements!
打字稿
for( i = 0; i < myEmployees.length; i++ ) {
const employee = myEmployees[i];
let magicNumber = employee.extraVacay;
let stillEmployed = employee.stillEmployed;
let timeInJob = employee.timeInJob;
let name = employee.name;
if( magicNumber > 30 && timeInJob > 5 && stillEmployed == true ) {
document.getElementById('win').innerHTML = (`Congratulations to ${name}, you have been here for ${timeInJob} years and you meet the magic number! You get 2 extra weeks of PTO!`);
}
else if (stillEmployed == true) {
document.getElementById('here').innerHTML = (`${name}, thank you for your service over the past ${timeInJob} years. I look forward to many more years working with you!`);
}
else {
document.getElementById('notHere').innerHTML = (`${name}, no longer works here.`)
}
};