function story1(){
var t=document.createElement('p');
t.innerHTML = "You wake up from your sleep in a half daze to hear noises of screams outside your bedroom window. You stumble over there to see what is the matter. You decide it's a good idea to grab your"+' <i onclick=addSword()> '+" sword "+' </i> '+"as you take the "+' <i onclick=story2()> '+" stairs. "+'</i>';
document.getElementById("story").appendChild(t);
}
function story2(){
var t = document.createElement('p');
t.innerHTML = "You realize that the door is locked and need to break the code in order to go outside." +' <i id="one" onclick=addOne()> '+ num1 +'</i>'+' <i id="two" onclick=addTwo()> '+ num2+'</i>'+' <i id="three" onclick=addThree()> '+ num3 +'</i>';
document.getElementById("story").appendChild(t);
var b = document.createElement('input');
b.type = 'button';
b.value = 'Check Code';
b.onclick = checkCode();
document.getElementById("story").appendChild(b);
}
要するに、これらの 2 つの関数は、私の問題がある場所です。コードが壊れているかどうかを確認するために、div 内にボタンを追加しようとしています。のコーディングcheckCode
はそのまま動作します。
問題は、checkCode()
ボタンの代わりに階段をクリックしたときに実際に機能していることです。私は試してみましb.on('click', checkCode())
たb.setAttribute('onclick', checkCode())
。
ボタンを正しくコーディングしていない可能性がありますが、チュートリアルや同様の問題に対する回答を読んでも、これまでのところしか理解できません! (笑)
前もって感謝します!