我想做一個小遊戲,但我沒有很多經驗。此外,我知道這可能是絕對不能做的最好辦法,因此,如果任何人有什麼適合初學者那簡直太好了爲什麼不是第二個功能工作?
<a id="key">There is a key on the floor</a>
<button onclick="keylol()">Pick it up</button>
<a id="door">You see a locked door</a>
<button onclick="doortext()">Try to open the door</button>
<script>
var key = 1
function keylol() {
document.getElementById("key").innerHTML = "You picked up the key";
var key = 2;
}
function doortext() {
if (key = 1) {
document.getElementById("door").innerHTML = "You cannot open a locked door";
} else {
document.getElementById("door").innerHTML = "You opened the door hooray";
}
}
</script>