好的,这就是现在的全部。
评论为“从这里开始”的部分给我带来了麻烦。它的其余部分也按我想要的方式工作,但我一生无法接受。我已经在Google上搜索了很多次,我被广告化了Java课程和编码类。
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<h1>Text adventure</h1>
<p>By Caleb Scott Sanders</p>
<p id="1"></p>
<p id="2"></p>
<p id="3"></p>
<script>
document.getElementById("demo").innnerHTML = confirm("Sup");
</script>
<script>
document.getElementById("1").innerHTML = "you wake up in a dark and dusty room, its cramped and only two potential exits. The door or the window.";
document.getElementById("2").innerHTML = "1: check door 2: check window";
</script>
<script>//From here
document.getElementById("demo").innerHTML =
choice = prompt();
if(choice = a){
document.getById("3").innerHTML = "The door has a large iron lock with equaly large bars. This seams more like a cell gate than a door...";
} else if(choice = b) {
document.getById("3").innerHTML = "The window is open but looks too small to crawl through. No way out from here.";
};
</script>
<p id="3"></p>// to here is the problem
</body>
</html>
请告诉我我做错了什么,因为我做不到。
最佳答案
问题是几件事...
我不知道您为什么使用document.getElementById("demo").innerHTML =
,但是不知道。
比较时使用三个等号,设置值使用一个等号。
用引号将a和b括起来,它们不是变量,而是字符串。
它是getElementById
而不是getById
。
为了将来参考,请尝试使用控制台,它将引导您正确的方向。
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<h1>Text adventure</h1>
<p>By Caleb Scott Sanders</p>
<p id="1"></p>
<p id="2"></p>
<p id="3"></p>
<script>
document.getElementById("demo").innnerHTML = confirm("Sup");
</script>
<script>
document.getElementById("1").innerHTML = "you wake up in a dark and dusty room, its cramped and only two potential exits. The door or the window.";
document.getElementById("2").innerHTML = "1: check door 2: check window";
</script>
<script>
var choice = prompt();
if(choice === "a"){
document.getElementById("3").innerHTML = "The door has a large iron lock with equaly large bars. This seams more like a cell gate than a door...";
}else if(choice === "b"){
document.getElementById("3").innerHTML = "The window is open but looks too small to crawl through. No way out from here.";
};
</script>
</body>
</html>
关于javascript - 我不知道如何做出两个选择来显示您的选择,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/36273138/