javascript - 计算机选择选项时图像不可见
问题描述
在此处输入图像描述问题是当计算机选择选项时,图像不可见,而人类选择的图像清晰可见。请帮我调试出问题的地方。它显示错误 ERR_FILE_NOT_FOUND。然而,人类选择的图像清晰可见。
function rpsGame(yourChoice) {
console.log(yourChoice);
console.log(yourChoice.src);
var humanChoice, botChoice;
humanChoice = yourChoice.id;
botChoice = numberToChoice(randToRpsInt());
console.log('Computer Choose ',botChoice)
results = decideWinner(humanChoice,botChoice);
console.log(results);
message =finalMessage(results);
console.log(message);
rpsFrontEnd(yourChoice.id,botChoice.in, message);
}
function randToRpsInt() {
return Math.floor(Math.random()*3)
}
function numberToChoice(number) {
return['stone','paper','scissor'][number]
}
function decideWinner(yourChoice,computerChoice) {
var rpsDatabase = {
'stone':{'stone':0.5,'paper':0,'scissor':1},
'paper':{'stone':1,'paper':0.5,'scissor':0},
'scissor':{'stone':0,'paper':1,'scissor':0.5}
};
var yourScore = rpsDatabase[yourChoice][computerChoice];
var computerScore = rpsDatabase[computerChoice][yourChoice];
return[yourScore,computerScore];
}
function finalMessage([yourScore,computerScore]) {
if (yourScore === 0) {
return{'message' : 'You Lost !', 'color': 'red'};
} else if(yourScore === 0.5) {
return{'message': 'You Tied !', 'color':'darkgoldenrod'};
} else {
return{'message': 'You Won !', 'color': 'green'};
}
}
function rpsFrontEnd(humanImageChoice,botImageChoice,finalMessage) {
var imageDatabase = {
'stone':document.getElementById('stone').src,
'paper':document.getElementById('paper').src,
'scissor':document.getElementById('scissor').src,
}
//removing the imgages after clicking on it
document.getElementById('stone').remove();
document.getElementById('paper').remove();
document.getElementById('scissor').remove();
var humanDiv = document.createElement('div');
var messageDiv = document.createElement('div');
var botDiv = document.createElement('div');
humanDiv.innerHTML = "<img src='" + imageDatabase[humanImageChoice] +"' height = 150 width = 150 style = 'box-shadow : 0px 10px 50px rgba(37,50,233,1;'>"
messageDiv.innerHTML = "<h1 style= 'color: " +finalMessage['color']+";font-size:60px;padding:30px;'>" + finalMessage['message'] + "</h1>"
botDiv.innerHTML = "<img src= '"+ imageDatabase[botImageChoice] + "' height=150 width=150 style='box-shadow:0px 10px 50px rgba(243,38,24,1);'>"
document.getElementById('flex-box-rps-div').appendChild(humanDiv);
document.getElementById('flex-box-rps-div').appendChild(messageDiv);
document.getElementById('flex-box-rps-div').appendChild(botDiv);
}
解决方案
rpsFrontEnd(yourChoice.id, botChoice, message); //将 botChoice.id 替换为 botChoice
推荐阅读
- c# - Dynamics CRM 中的 CalculatePrice 消息
- webpack - 如何使用 babel 和 webpack 进行动态代码拆分?
- ios - Firebase DebugView iOS 设备名称
- google-apps-script - 如何使用 Google Script 检查安全设置?
- amazon-web-services - aws cli 命令更改默认 sing in 方法
- postgresql - (postgreSQL 9.5)使用 make_date 奇数插入带有日期列的表
- reactiveui - 用 ReactiveUI Observable 包装 IEnumerable
- google-bigquery - 在 BigQuery SQL 中,加入和过滤第二个表的最有效方法通常是什么?
- python - Python has_key 的算法复杂度
- javascript - Chrome 扩展 IndexedDB 删除功能不起作用