如何将输出打印为
1天内17个
2天内21个
3天内23个
而不是
0 天后 17 个
1天内21个
2天内23个
const arr = [17, 21, 23];
const printForecase = function() {
for (let i = 0; i < arr.length; i++) {
console.log(`${arr[i]} in ${i} days`);
} }
printForecase();
由于索引是从0开始的,所以当你在
console.log()
(${i+1}
)中打印时只需添加一(1)即可
const arr = [17, 21, 23];
const printForecase = function() {
for (let i = 0; i < arr.length; i++) {
console.log(`${arr[i]} in ${i+1} days`);
} }
printForecase();
你可以用 {i} 加 1
const arr = [17, 21, 23];
const printForecase = function() {
for (let i = 0; i < arr.length; i++) {
console.log(`${arr[i]} in ${i+1} days`);
} }
printForecase();
控制台.log(
${arr[i]} in ${i+1} days
)
const arr = [17, 21, 23];
const printForecase = function() {
for (let i = 0; i < arr.length; i++) {
console.log(`${arr[i]} in ${i+1} days`);
} }
printForecase();
const arr = [17,21,23];
const printForecase = ()=>{
let days = 1;
for(let newarr of arr){
console.log(`${newarr} in ${ days++ } Days`)
}
}
printForecase()
怎么了,哈哈,我一个月前就解决了,但后来我忙了几个星期,所以我决定复习几节课,我真的很难坚持这个,看起来超级简单,正如我提到的,之前已经解决了它,但现在无法做到这一点,所以开始寻找提示。