文章目錄
- style.display
- innerText
- 學到的代碼寫法
- 小總結
style.display
使用元素的 style.display 屬性,將屬性的值設置為 “block” 或 “none”,可以顯示或隱藏元素。
resetGameBtn.style.display = 'block';
optionsContainer.style.display = 'none';
innerText
使用 innerText 屬性來更新元素的內容。
要清除元素的內容,可以將 innerText 設置為空字符串。
playerScoreSpanElement.innerText = '';
學到的代碼寫法
function hasPlayerWonTheRound(player, computer) {return ((player === "Rock" && computer === "Scissors") ||(player === "Scissors" && computer === "Paper") ||(player === "Paper" && computer === "Rock"));
}
winnerMsgElement.innerText = `${playerScore === 3 ? "Player" : "Computer"} has won the game!`;
rockBtn.addEventListener("click", function () {showResults("Rock");
});
function getRandomComputerResult() {const options = ["Rock", "Paper", "Scissors"];const randomIndex = Math.floor(Math.random() * options.length);return options[randomIndex];
}
小總結
document.getElementById("winner-msg");
cdocument.querySelector(".options-container");
resetGameBtn.style.display = "block";
optionsContainer.style.display = "none";
playerScoreSpanElement.innerText = playerScore;
resetGameBtn.addEventListener("click", resetGame);
rockBtn.addEventListener("click", function () {showResults("Rock");
});