這裏是我的代碼:的JavaScript。加入不工作
board = [];
var rowsNum = 5;
var colsNum = 5;
function printBoard(board) {
for (row in board) {
document.write(" ").join(row);
}
}
function clearAndRestartBoard() {
board = [];
for (i = 0; i < rowsNum; i++) {
board.push("[ ]" * colsNum);
}
}
printBoard(board);
它不會拋出一個錯誤,但它並不在我的網頁上顯示出來。你知道我做錯了什麼嗎?
以防萬一,這裏是沒有的CSS的HTML:
<!DOCTYPE html>
<html>
<head>
<link href="test.css" type="text/css"rel="stylesheet" />
<title> Test! </title>
</head>
<body>
<p id = "script"> <script src = "test.js"> </script> </p>
</body>
</html>
我是很新的JS所以非常感謝你的幫助!
你'board'變量是一個空數組。然後'「[]」* colsNum'不符合你的想法。 – zerkms
你到底想做什麼? – iplus26
https://jsfiddle.net/arunpjohny/h294wre3/1/ –