for(let i=0;i<10;++i){
for(let j=0;j<10;++j){
if((i+j)%2==0){
document.write("#");
}else {
document.write("0");
}
}
document.write("<br>");
}
</script> <!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>国际象棋棋盘</title>
</head>
<body>
<button type="button" name="button" onclick="getchessboard()">输出棋盘</button>
<p id="result"></p>
<script>
function getchessboard(){
var str = "";
for (var i=0; i<8; i++){
for (var j=0; j<8; j++){
if ((i+j) % 2 == 0){
str += "#";
}
else {
str += "0";
}
}
str += '<br/>';
}
document.getElementById("result").innerHTML = str;
}
</script>
</body>
</html> 康康 let str = '';
for (let i = 0; i <= 16; i++) {
for (let j = 0; j <= 16; j++){
if((j + i)%2 == 0) {
str+='#'
}else {
str+='o'
}
}
str+='\n'
}
console.log(str)
你们都不想一下的么? 谢谢大佬 谢谢 哦吼 do'nt know 1 本帖最后由 KeyError 于 2023-1-13 15:07 编辑
第一种方法:
document.write('#0#0#0#0\n');
document.write('0#0#0#0#\n');
document.write('#0#0#0#0\n');
document.write('0#0#0#0#\n');
document.write('#0#0#0#0\n');
document.write('0#0#0#0#\n');
document.write('#0#0#0#0\n');
document.write('0#0#0#0#\n');
第二种:
for(var i=0;i<=7;i++){
for(var j=0;j<=7;j++){
if((i * 8 + j) % 2== 0){
document.write('0');
} else {
document.write('#');
}
}
document.write('\n');
} 看看
页:
1
[2]