我不知道如何做出两个选择,然后展示你的选择

I cant figure out how to make two choices then show what your choice was

本文关键字:选择 然后 你的选择 两个 何做出 我不知道      更新时间:2023-09-26

好吧,这就是现在的全部内容。评论"从这里开始"的部分给我带来了麻烦。剩下的也按我想要的方式工作,但我一辈子都做不到。我已经在谷歌上搜索了很多次了,我被宣传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>

请告诉我我做错了什么,因为我做不到。

问题在于。。。

  1. 我不知道你为什么要用document.getElementById("demo").innerHTML =,但不要。

  2. 使用三个等号进行比较,一个等号用于设置值。

  3. 用引号把a和b括起来,它们不是变量,而是字符串。

  4. 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>