我正在尝试开发一个简单的使用Javascript的在线文字游戏。我现在已经过了,但现在我陷入了困境。基本上游戏的第一部分是显示十个单词,它是描述。在javascript中保持分数
然后用户可以点击“测试我”按钮,将被导向到我称为testme.html的页面,在那里我将显示一个描述,然后,他们可以选择四个单词。一旦玩家点击下一个描述出现的按钮,我的描述就会正常工作。现在,我需要能够切换多种选择,并且还可以创建一个功能,让我可以看到他们是否选择了正确或错误的单词,然后最终可以显示他们有多少正确或错误的例子:你有9/10的权利。
这里是主页:http://alexallin.com/wordgame/
这里是testme.html页:http://alexallin.com/wordgame/Testme.html
var ThisText = 0;
var Words = [ { word: '1. Amicable', definition: 'friendly, agreeable.' },
{ word: '2. acumen', definition: 'the ability to make good judgments and quick decisions, typically in a particular domain.' },
{ word: '3. accoutrements', definition: 'additional items of dress or equipment, or other items carried or worn by a person or used for a particular activity.' },
{ word: '4. Abstinence', definition: 'the act of refraining from pleasurable activity, e.g., eating or drinking.' },
{ word: '5. Adulation', definition: 'high praise.' },
{ word: '6. Adversity', definition: 'misfortune, an unfavorable turn of events.' },
{ word: '7. Aesthetic', definition: 'pertaining to beauty or the arts.' },
{ word: '8. Anachronistic', definition: 'out-of-date, not attributed to the correct historical period.' },
{ word: '9. Anecdote', definition: 'short, usually funny account of an event.' },
{ word: '10. Antagonist', definition: 'foe, opponent, adversary.' },
];
function ChangeWordTo(NextWord) {
document.getElementById('Answer_Box_One').innerHTML = NextWord;
}
// this grabs the ID description
function ChangeDescriptionTo(NextDescription) {
document.getElementById('description').innerHTML = NextDescription;
}
// This loads it to the first definition...
function onLoad() {
switchTo(0);
}
// won't work with out
function switchTo(which) {
ChangeWordTo(Words[which].word);
ChangeDescriptionTo(Words[which].definition);
}
// This increments as button is click
function ShowDesc() {
ThisText++;
switchTo(ThisText);
}
下面是HTML代码-------------- ----------
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="main.css">
<script src="score.js"></script>
</head>
<body onload="onLoad();">
<div id="main">
<div>
<center><p id="description">Read the Discription and chose your answer below.</p></center>
</div>
<br/>
<!--
<div id="Answer_Box">
<center>
<form>
<input type="checkbox" name="vehicle" value="text" id="Answer_Box_One">I have a bike
</form>
-->
<form>
<center>
<div style="float: left; width: 50%;">
<ul>
<label id="Answer_Box_One" for="male">Male</label>
<input type="radio" name="sex" id="male" value="male"><br>
<label id="Answer_Box_Two" for="male">Female</label>
<input type="radio" name="sex" id="male" value="Female"><br>
</ul>
</div>
<div style="float: right; width: 50%;">
<ul>
<label id="Answer_Box_Three" for="male">Male</label>
<input type="radio" name="sex" id="male" value="male"><br>
<label id="Answer_Box_Four" for="Not Above">Not Above</label>
<input type="radio" name="sex" id="Not Above" value="Not Above"><br>
</ul>
</div>
<button type="button" onclick="ShowDesc();">Correct</button>
</center>
</form>
</center>
</div>
</div>
</body>
</html>
呃...所以你想让我们......建立你的程序?我在这里没有看到任何相关的代码** **测试我**,**切换多个选择**,**选择了正确或错误的单词**,或**你有9/10右**。这是很多问题的萌芽。 –
不能理解你的游戏...你正在显示的话和描述,然后你测试什么?为什么你不使用全局变量来维护分数... – Saurabh
这主要是为了练习。一旦我开始工作,我会将描述转换成一个句子,填入空白类型的问题,如下所示(什么是1 + 1 = _________)。是的,我完全陷入困境,我没有要求某人为我编写程序,但有人请指导我如何完成此任务。我一直在努力。我无法自己弄清楚,我需要帮助。谢谢@Saurabh –