我正在尝试让我的JavaScript文件在我的网页上正常运行,并且它在我尝试的前几次做了。然而,在那之后,当我尝试按下按钮时,没有任何反应。
HTML:
<!DOCTYPE html>
<head>
<title>Stevo's Website</title>
<link rel='stylesheet' href='style.css'/>
<script LANGUAGE="JavaScript" src="C:\Users\Steven\Desktop\website\rockScissorPaper.js"></script>
</head>
<body class="body">
<div class="navbar">
<ul class="pull-left">
<li><a href="website.html" id="navtabnow">Owl</a>
<ul>
<li><a href="#1">Test1</a></li>
<li><a href="#2">Test2</a></li>
</ul>
</li>
<li><a href="news.html" id="norightborder">Wolf</a></li>
<li><a href="#">About</a>
<ul>
<li><a href="#1" onclick="compare()">Test1</a></li>
<li><a href="#2" onclick="compare()">Test2</a></li>
</ul>
</li>
</ul>
<ul class="pull-right">
<li><a href="javascript:compare();">Login</a></li>
<li><a href="#signup">Sign Up</a></li>
<li><a href="#support">Support</a></li>
</ul>
</div>
<div class="jumbotron">
</div>
</body>
使用Javascript:
var compare = function()
{
var userChoice = prompt("Do you choose rock, paper or scissors?");
userChoice = userChoice.toLowerCase();
alert(userChoice);
if (userChoice != "rock" && "paper" && "scissors")
{
alert("You need to choose rock, paper or scissors.");
}
else
{
var computerChoice = Math.random();
if (computerChoice < 0.34)
{
computerChoice = "rock";
}
else if (computerChoice <= 0.67)
{
computerChoice = "paper";
}
else
{
computerChoice = "scissors";
}
choice1 = userChoice;
choice2 = computerChoice.toLowerCase;
if (choice1 === choice2)
{
return "The result is a tie!";
}
//choice1 is rock
else if (choice1 === "rock")
{
if (choice2 === "scissors")
{
alert("The computer chose: " + computerChoice + "\nRock wins!");
}
else if (choice2 === "paper")
{
alert("The computer chose: " + computerChoice + "\nPaper wins!";
};
}
//choice1 is paper
else if (choice1 === "paper")
{
if (choice2 === "rock")
{
return "Paper wins!";
}
else if (choice2 === "scissors")
{
return "Scissors wins!";
};
}
//choice1 is scissors
else if (choice1 === "scissors")
{
if (choice2 === "paper")
{
return "Scissors wins!";
}
else if (choice2 === "rock")
{
return "Paper wins!";
};
};
};
};
不介意布局等,因为我没有将我的CSS和其他html文件放在JsFiddle中。关键是我的javascript应该在按下其中一个临时测试按钮时运行。 (关于:Test1,关于:Test2&amp;登录)
我尝试过几种不同的东西,你也可以说,但由于某种原因,我无法让它再次发挥作用。
答案 0 :(得分:0)
else if (choice2 === "paper")
{
alert("The computer chose: " + computerChoice + "\nPaper wins!";
};
你有未公开的支架&#34;)&#34;试着修理它。