我不知道如何做出两个选择,然后展示你的选择
I cant figure out how to make two choices then show what your choice was
好吧,这就是现在的全部内容。评论"从这里开始"的部分给我带来了麻烦。剩下的也按我想要的方式工作,但我一辈子都做不到。我已经在谷歌上搜索了很多次了,我被宣传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>
相关文章:
- 什么是“;选择“;然后触发事件
- 如何利用多链接延迟检查并显示ping结果,然后使用JavaScript选择最快的URL
- 选择值,然后只调用函数
- onchange选择get value并执行查询,然后在同一页面上显示结果
- 椭圆字幕选择,然后在Photoshop中使用Javascript填充颜色
- 选择具有ID的父级的第一个子级以外的所有子级,然后应用操作
- 通过属性名称选择每个td,然后给出'未定义'用于属性值
- 在输入字段中选择一个值,然后用相应的数据填充另一个字段
- Angular js,在选择元素上,我想 POST 数据以将其保存在数据库中,然后我想使用 PUT 更新它而无需重新加载
- 单击“选择标签”中的“选项”时创建,然后选中“值”创建输入
- 创建唯一选项,然后使用 JavaScript 填充多个选择
- 选择其中一个单选按钮,然后单击“提交”,重定向其他页面
- 从select中选择一个选项,然后使用Codeigniter在另一个选择框上显示数据
- Jquery页面重新加载,然后选择分区
- 如果选择'其他'然后填充输入字段
- 下拉菜单,用于选择国家/地区,然后选择州
- 我不知道如何做出两个选择,然后展示你的选择
- 文本框和选择框组合单个文本中的值(第一个tb值,然后是sb值)
- Jquery按类选择然后匹配值
- 选择x + y然后返回文本字符串