调用函数时,我的条件文本没有反映在页面上

问题描述 投票:0回答:1

const text = document.getElementById('text');

函数 playGame(玩家移动){

computerMove = pickComputerMove(); 让结果 = '';

if (playerMove === 'heads') {
    if (computerMove === 'heads') {
        result = 'You win';
    } 
 else if(computerMove === 'tails'){
       result = 'You lose';
    }
}
else if(playerMove === 'tails'){
    if (computerMove === 'heads') {
        result = 'You lose';
    } 
    else if(computerMove === 'tails'){
       result = 'You win';
    }
}
text.innerText = result;

}

结果变量似乎没有定义,我做错了什么?

javascript html if-statement innertext
1个回答
0
投票

尝试将“const”更改为“var”

© www.soinside.com 2019 - 2024. All rights reserved.