用JS编写出一下两个测试题:1、打印出1000-2000年中所有的闰年并以每行四个数的形式输出 。2、使用 打印三角形要求输出到网页上第一行一个第二行2个以此类推。
第一题代码:
for(let year = 1000; year <= 2000; year++){
if(year % 4 === 0 && year % 100 !== 0 || year % 400 === 0){
document.write(year + ' ');
if((year - 999) % 4 === 0){
document.write('<br>');
}
}
}
第二题代码:
for(let i = 1; i <= 5; i++){
for(let j = 1; j <= i; j++){
document.write('*');
}
document.write('<br>');
}
原文地址: https://www.cveoy.top/t/topic/b2jA 著作权归作者所有。请勿转载和采集!