RPS游戏应用程序不工作
RPS Game App Not Working
我正在开发一款RPS游戏,在设计它之前,我在让它在基本级别上运行时遇到了一些麻烦
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="rpsfinal1.css">
<title>Shattered Template</title>
</head>
<body>
<div class="corners">
<h1 class="title">Rock Paper Scissors!</h1>
<p>Welcome to a Rock Paper Scissors web app!1
</p>
<script type="text/javascript" src="rps.js"></script>
<a href='linkhref.html' id='mylink'>Play Again</a>
<input type="button" value="Rock" onClick="rockChoice()">
<input type="button" value="Paper" onclick="paperChoice()">
<input type="button" value="Scissors" onClick="scissorsChoice()">
<p id="output"></p>
</div>
</body>
</html>
这是我的JS:
var compare = function(choice1,choice2) {
if (choice1 === "rock") {
if (choice2 === "rock") {
console.log("It is a tie! The computer chose rock!");
alert ("It is a tie!");
}
else if (choice2 === "paper") {
console.log ("Sorry, you loose. :(");
alert ("Sorry, you lose. :( The computer chose paper!");
}
else {
console.log ("You win!");
alert ("You win! The computer chose scissors!");
}
}
else if (choice1 === "paper") {
if (choice2 === "rock") {
console.log ("You win!");
alert ("You win! The computer chose rock!");
}
else if (choice2 === "paper") {
console.log ("It is a tie!");
alert ("It is a tie! The computer chose paper!");
}
else {
console.log("Sorry, you lose. :(");
alert ("Sorry, you lose. :( The computer chose scissors!");
}
}
else {
if (choice2 === "rock") {
console.log ("You win!");
alert ("You win! The computer chose rock!");
}
else if (choice2 === "paper") {
console.log ("Sorry, you lose. :(");
alert ("Sorry, you lose. :( The computer chose paper!");
}
else {
console.log ("It is a tie!");
alert ("It is a tie! The computer chose scissors!");
}
}
};
var rockChoice = function() {
var userChoice = "rock";
var computerChoice = Math.random();
console.log(computerChoice);
if (computerChoice >= 0 && computerChoice <= 0.33) {
computerChoice = "rock";
console.log(computerChoice);
}
else if (computerChoice >= 0.34 && computerChoice <= 0.66) {
computerChoice = "paper";
console.log(computerChoice);
}
else {
computerChoice = "scissors";
console.log(computerChoice);
}
compare(userChoice,computerChoice);
}
var paperChoice = function() {
var userChoice = "paper";
var computerChoice = Math.random();
console.log(computerChoice);
if (computerChoice >= 0 && computerChoice <= 0.33) {
computerChoice = "rock";
console.log(computerChoice);
}
else if (computerChoice >= 0.34 && computerChoice <= 0.66) {
computerChoice = "paper";
console.log(computerChoice);
}
else {
computerChoice = "scissors";
console.log(computerChoice);
}
compare(userChoice,computerChoice);
}
var scissorsChoice = function() {
var userChoice = "scissors";
var computerChoice = Math.random();
console.log(computerChoice);
if (computerChoice >= 0 && computerChoice <= 0.33) {
computerChoice = "rock";
console.log(computerChoice);
}
else if (computerChoice >= 0.34 && computerChoice <= 0.66) {
computerChoice = "paper";
console.log(computerChoice);
}
else {
computerChoice = "scissors";
console.log(computerChoice);
}
compare(userChoice,computerChoice);
}
我认为代码不起作用的原因是我可能没有正确调用函数。请告诉我。谢谢
我知道现在有点晚了,但对于那些正在寻找同样东西的人来说:-您可能会遇到"语法错误",因为在JS文件的脚本末尾有一个额外的括号(})。
相关文章:
- 使用谷歌应用程序脚本从工作表中获取值并将其显示在文本框中
- firefox插件:退出不工作的应用程序观察器
- 为什么Turbolinks不能正常工作?Rails应用程序
- 谷歌表单-根据分配给谷歌应用程序的工作为商业用户预先填充多项选择列表
- angular js应用程序不工作
- 应用程序在“关闭”之后停止工作(控制台中没有错误);咕哝的构造”;
- 只需添加一个'允许跨来源请求'到我的节点应用程序工作
- 我应该将哪些数据传递给 Spotify 应用程序才能使分页工作
- 如何让应用程序帮助程序方法在发送的请求为 JS 格式时工作
- 最基本的 Angular 应用程序无法正常工作
- WebSocket 应用程序在部署在 Tomcat8 服务器上时无法正常工作
- 离子应用程序在浏览器上运行,但在我的安卓设备中无法正常工作
- 谷歌应用程序脚本-正在尝试使用getUrl.TypeError:在对象工作表中找不到函数getUrl
- cyrillic单词的Regexp不'无法在应用程序中工作
- 提示不在谷歌应用程序脚本中工作
- 为什么我的UI应用程序嵌套在引导模式中时无法工作
- Javascript和jQuery在Grails应用程序中停止工作
- 我的javascript问答应用程序;工作不正常
- 如何在ExtJS中构建无需鼠标即可工作的应用程序
- Backbone.js应用程序使用CommonJS结构与node.js和客户端协同工作