html 显示文本 循环,javascript – 用于循环覆盖HTML中的文本

我的名为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.`)

}

};

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值