1 =岩石
2 =纸
3 =剪刀
当我使用JSLint检查我的代码是否有错误时,它向我抛出一大堆消息,说我的一些函数超出了范围。我已经花了2个小时摆弄代码试图让它工作,但无济于事。也许有人可以用新鲜的眼睛看一看。谢谢。
var computerchoice = 0;
var humanchoice = 0;
var computerscore = 0;
var humanscore = 0;
var roundnumber = 0;
var tiescore = 0;
var获胜者;
var loser;
function SwitchToGameScreen() {
document.getElementById("startscreen").style.display = "none";
document.getElementById("gamescreen").style.display = "block";
}
function resetgame() {
document.getElementById("humanrock").style.border = "none";
document.getElementById("humanpaper").style.border = "none";
document.getElementById("humanscissor").style.border = "none";
document.getElementById("computerrock").style.border = "none";
document.getElementById("computerpaper").style.border = "none";
document.getElementById("computerscissor").style.border = "none";
}
function human_chooses_rock() {
humanchoice = 1;
document.getElementById("rock").style.border = "thick solid #0000FF";
document.getElementById("humanchoice").innerHTML = "Rock";
EvaluateRound;
}
function human_chooses_paper() {
humanchoice = 2;
document.getElementById("paper").style.border = "thick solid #0000FF";
document.getElementById("humanchoice").innerHTML = "Paper";
EvaluateRound;
}
function human_chooses_scissor() {
humanchoice = 3;
document.getElementById("scissor").style.border = "thick solid #0000FF";
document.getElementById("humanchoice").innerHTML = "Scissor";
EvaluateRound;
}
function EvaluateRound() {
roundnumber = roundnumber + 1;
computerchoice = Math.floor(Math.random() * 6) + 1;
if (humanchoice === 1 && computerchoice === 1) {
tiescore = tiescore + 1;
winner = "nobody";
UpdateStats();
}
if (humanchoice === 1 && computerchoice === 2) {
computerscore = computerscore + 1;
winner = "Computer";
UpdateStats();
}
if (humanchoice === 1 && computerchoice === 2) {
humanscore = humanscore + 1;
winner = "Human";
UpdateStats();
}
if (humanchoice === 2 && computerchoice === 1) {
humanscore = humanscore + 1;
winner = "Human";
UpdateStats();
}
if (humanchoice === 2 && computerchoice === 2) {
tiescore = tiescore + 1;
winner = "nobody";
UpdateStats();
}
if (humanchoice === 2 && computerchoice === 3) {
computerscore = computerscore + 1;
winner = "Computer";
UpdateStats();
}
if (humanchoice === 3 && computerchoice === 1) {
computerscore = computerscore + 1;
winner = "Computer";
UpdateStats();
}
if (humanchoice === 3 && computerchoice === 2) {
humanscore = humanscore + 1;
winner = "Human";
UpdateStats();
}
if (humanchoice === 3 && computerchoice === 3) {
tiescore = tiescore + 1;
winner = "nobody";
UpdateStats();
}
if (roundnumber === 10) {
document.getElementById("gamescreen").style.display = "none";
document.getElementById("finishscreen").style.display = "block";
UpdateStats();
}
if (computerchoice === 1) {
document.getElementById("computerrock").style.border = "thick solid #0000FF";
}
if (computerchoice === 2) {
document.getElementById("computerpaper").style.border = "thick solid #0000FF";
}
if (computerchoice === 3) {
document.getElementById("computerscissor").style.border = "thick solid #0000FF";
}
}
function UpdateStats() {
document.getElementById("humanscore").innerHTML = humanscore;
document.getElementById("computerscore").innerHTML = computerscore;
document.getElementById("tiescore").innerHTML = tiescore;
document.getElementById("roundnumber").innerHTML = roundnumber;
document.getElementById("computerchoice").innerHTML = computerchoice;
document.getElementById("winner").innerHTML = winner;
} document.getElementById("hidestartscreenshowgamescreen").addEventListener("click", SwitchToGameScreen);
document.getElementById("rock").addEventListener("click",human_chooses_rock);
document.getElementById("paper").addEventListener("click",human_chooses_paper);
document.getElementById("scissor").addEventListener("click",human_chooses_scissor);
document.getElementById("rock").addEventListener("click", resetgame);
document.getElementById("paper").addEventListener("click", resetgame);
document.getElementById("scissor").addEventListener("click", resetgame);