嗨我想把我的圖像從我的電腦放入我的搖滾紙剪刀遊戲,但我遇到了麻煩,它只是不會工作我不知道我哪裏錯了。 以及當我把圖像放在那裏的時候,我不得不從我的代碼中取出我的警告,以便它能夠工作,我將包括我的JavaScript和我的HTML以及我的小提琴。 我遇到了很多麻煩,我真的陷入困境,真的遇到了麻煩。岩石,剪刀。圖像不工作
的JavaScript
var differentOptions = ["rock", "paper", "scissors"];
var scores = [0, 0, 0, 0];
function Picks(id) {
var choice1 = id;
var imagePlayer = "<img='rps-paper" + "<img='rsp-rock" + "<img='rps-scissors" + choice1 + ".gif' />";
var choice2 = computerGenerate();
var imageComputer = "<img='rps-paper" + "<img='rsp-rock" + "<img='rps-scissors" + choice2 + ".gif' />";
alert ("You chose " + choice1 + ". The computer chose " + choice2 + "! " + compare(choice1, choice2));
document.getElementById('player').innerHTML = imagePlayer;
document.getElementById('computer').innerHTML = imageComputer;
displayScores();
}
function computerGenerate() {
var num = [Math.floor(Math.random() * 3)]
var computerChoice = differentOptions[num];
return computerChoice;
}
function compare(choice1, choice2) {
if (choice1 == choice2) {
scores[0]++;
scores[3]++;
return (" Draw You both picked the same! Try again!");
} else if (choice1 == "rock") {
if (choice2 == "scissors") {
scores[1]++;
scores[3]++;
return ("You Win!");
} else {
scores[2]++;
scores[3]++;
return ("You Lose!");
}
} else if (choice1 == "paper") {
if (choice2 == "rock") {
scores[1]++;
scores[3]++;
return ("You Win!");
} else if (choice2 == "scissors") {
scores[2]++;
scores[3]++;
return ("You Lose!");
}
} else if (choice1 == "scissors") {
if (choice2 == "rock") {
scores[2]++;
scores[3]++;
return ("You Lose!");
} else if (choice2 == "paper") {
scores[1]++;
scores[3]++;
return ("You Win!");
}
}
}
function displayScores() {
document.getElementById("wins").innerHTML = "Wins: " + scores[1];
document.getElementById("loss").innerHTML = "Losses: " + scores[2];
document.getElementById("ties").innerHTML = "Ties: " + scores[0];
document.getElementById("games").innerHTML = "Games Played: " + scores[3];
}
function resetScores() {
scores = [0, 0, 0, 0];
displayScores();
}
這是我的HTML。
<div style="text-align: center;">
<div id="optionsPanel">
<h1 class="title">Let's Play Rock/Paper/Scissors!</h1>
<div id="computer"></div>
<br/>
<div id="player"></div>
<button id="rockButton" class="button" onclick='userPicks("rock")'>Rock</button>
<button id="paperButton" class="button" onclick='userPicks("paper")'>Paper</button>
<button id="scissorsButton" class="button" onclick='userPicks("scissors")'>Scissors</button </div>
<div id="scoresPanel">
<h2 class="title">Scores:</h2>
<div id="wins" class="scores">Wins:</div>
<div id="loss" class="scores">Losses:</div>
<div id="ties" class="scores">Ties:</div>
<div id="games" class="scores">Games Played:</div>
<h2 class="button" onclick='resetScores();'>Reset</h2>
</div>
這是我的CSS。
#player, #computer {
border: 1px solid black;
height: 100px;
width: 150px;
margin: 10px;
}
好的,謝謝,我會給它一個 – Matthew 2014-10-05 06:34:48
我試圖保持它簡單,並沒有多少改變原來的代碼。我添加了標題,因爲它可以讓我們更容易地看到,而無需添加我自己的圖像 – mplungjan 2014-10-05 06:36:26
我如何將圖像添加到它只是想知道,因爲我無法讓我的圖像加載到它。 – Matthew 2014-10-05 06:38:10