所以我追蹤到我的問題,功能chargeBmAttk()
無法正常工作,所以我添加了一個警報,以創建一個更容易的調試指示;但是,警報不會彈出。功能chargeBmAttk()
的語法或HTML代碼中的按鈕有什麼問題嗎? 功能沒有運行
var playerHp = 45; // Player's health
var enemyHp = 35; // Enemy's health
// Player attack options
function missleAttk()
{
var playerDmgs = [5, 10, 15]; // Array of possible damages
var playerRndDmg = playerDmgs[Math.floor(Math.random() * playerDmgs.length]; // Randomly select integer from array and apply as playerRndDmg
enemyHp = enemyHp - playerRndDmg;
}
function chargeBmAttk()
{
alert("hello world");
// enemyHp = enemyHp - 5;
}
function waveBmAttk()
{
enemyHp = enemyHp - 7;
}
function iceBmAttk()
{
enemeyHp = enemeyHp - 10;
}
// Enemy attack options
function enemyAttk()
{
var enemyDmgs = [10, 7, 5, 4]; // Array of possible enemy damages
var enemyrRndDmg = enemyDmgs[Math.floor(Math.random() * enemyDmgs.length]; // Randomly select integer from array and apply as enemyRndDmg
playerHp = playerHp - enemeyRndDmg;
}
// Change txt outputs
function changePlayerHp()
{
var oldHp = document.getElementById("disPlayerHp").innerHTML;
var newHp = "Samus" + playerHp + "/ 45";
document.getElementById("disPlayerHp").innerHTML = newHp;
}
function changeEnemyHp()
{
var oldHp = document.getElementById("disEnemyHp").innerHTML;
var newHp = "Metroid" + enemyHp + "/ 35";
document.getElementById("disEnemyHp").innerHTML = newHp;
}
// Game end functions
function win()
{
if (enemyHp <= 0){
alert ("You win!");
}
}
function lose()
{
if (playerHp <= 0){
alert ("You Lose!");
}
}
// Game flow
function flow()
{
changeEnemyHp();
enemyAttk();
changePlayerHp();
win();
lose();
}
</script>
</head>
<body>
<div class="actions">
</br>
<input type="button" onclick = "chargeBmAttk()" value = "Charge Beam">
</button>
</div>
</body>
什麼是''在那裏做? – yogi 2013-02-25 06:39:22
您是否已經在firefox或谷歌瀏覽器中檢查過開發者控制檯(Web控制檯)的輸出?應該有關於JavaScript的一些錯誤消息,我想... – mooonli 2013-02-25 06:39:38