重复我知道:石头剪刀布代码学院。为什么提示没有出现?
Repetitive I know: Rock Paper Scissors Code academy. Why does the prompt not show up?
看来我下面的提示没有出现。我无法让这段代码工作。我仍然是一名初学者,但我已经编码了大约 3 个月了。
<html>
<title>Random Code</title>
<head>
<style>
body {
background-color: green;
color: white;
}
</style>
<script>
var userChoice = prompt("Choose Rock Paper or Scissor!").toUpperCase();
//this prompt is not showing up.
var computerChoice = Math.random();
if (computerChoice < .34) {
computerChoice = "ROCK";
} else if (computerChoice > .33 && computerChoice <= .67) {
computerChoice = "PAPER";
} else {
computerChoice = "SCISSORS";
}
document.write("Computer: " + computerChoice);
var compare = function (choice1, choice2) {
if (choice1 === choice2) {
return ("The result is a tie!")
} else if (choice1 === "ROCK" && choice2 === "PAPER") {
return ("The computer chose:" + computerChoice + ". You lose");
} else if (choice1 === "ROCK" && choice2 === "SCISSORS") {
return ("The computer chose:" + choice2 + ". You win!");
} else if (choice1 === "PAPER" && choice2 === "ROCK") {
return ("The computer chose:" + choice2 + ". You lose.");
} else if (choice1 === "PAPER" && choice2 === "SCISSORS") {
return ("The computer chose:" + choice2 + ". You lose.");
} else if (choice1 === "SCISSORS" && choice2 === "ROCK") {
return ("The computer chose:" + choice2 + ". You lose.");
} else if (choice1 === "SCISSORS" && choice2 === "PAPER") {
return ("The computer chose:" + computerChoice + ". You win!");
} else {
return ("You entered an invalid input");
}
}
document.write("User choice: " + userChoice);
document.write("Computer choice: " + computer Choice);
document.getElementById("rps").innerHTML = compare(userChoice, computerChoice);
</script>
</head>
<body>
<p id="rps"></p>
</body>
</html>
如果您有任何指点或建议,我将永远感激不已!
这听起来可能很愚蠢,但您是否选中了提示 'prevent this page from creating additional dialogues' 中的框。在隐身页面中试用您的应用。
行
document.write("Computer choice: " + computer Choice);
应该是
document.write("Computer choice: " + computerChoice);
您还应该移动页面底部的脚本。
<html>
<title>Random Code</title>
<head>
<style>
body {
background-color: green;
color: white;
}
</style>
</head>
<body>
<p id="rps"></p>
<script>
var userChoice = prompt("Choose Rock Paper or Scissor!").toUpperCase();
//this prompt is not showing up.
var computerChoice = Math.random();
if (computerChoice < .34) {
computerChoice = "ROCK";
} else if (computerChoice > .33 && computerChoice <= .67) {
computerChoice = "PAPER";
} else {
computerChoice = "SCISSORS";
}
document.write("Computer: " + computerChoice);
var compare = function(choice1, choice2) {
if (choice1 === choice2) {
return ("The result is a tie!")
} else if (choice1 === "ROCK" && choice2 === "PAPER") {
return ("The computer chose:" + computerChoice + ". You lose");
} else if (choice1 === "ROCK" && choice2 === "SCISSORS") {
return ("The computer chose:" + choice2 + ". You win!");
} else if (choice1 === "PAPER" && choice2 === "ROCK") {
return ("The computer chose:" + choice2 + ". You lose.");
} else if (choice1 === "PAPER" && choice2 === "SCISSORS") {
return ("The computer chose:" + choice2 + ". You lose.");
} else if (choice1 === "SCISSORS" && choice2 === "ROCK") {
return ("The computer chose:" + choice2 + ". You lose.");
} else if (choice1 === "SCISSORS" && choice2 === "PAPER") {
return ("The computer chose:" + computerChoice + ". You win!");
} else {
return ("You entered an invalid input");
}
}
document.write("User choice: " + userChoice);
document.write("Computer choice: " + computerChoice);
document.getElementById("rps").innerHTML = compare(userChoice, computerChoice);
</script>
</body>
</html>
当我 运行 你在 jsfiddle 中的代码并注释掉除第一个之外的所有内容时,它工作正常。 "fiddling" 之后我发现了你的错误。第 34 行有
document.write("Computer choice: " + computer Choice);
而不是
document.write("Computer choice: " + computerChoice);
var userChoice = prompt("Choose Rock Paper or Scissor!", "rps").toUpperCase();
//this prompt is not showing up.
var computerChoice = Math.random();
if (computerChoice < .34){
computerChoice = "ROCK";
} else if (computerChoice > .33 && computerChoice <= .67){
computerChoice = "PAPER";
}else{
computerChoice = "SCISSORS";
}document.write("Computer: " + computerChoice);
var compare = function(choice1, choice2){
if (choice1 === choice2){
return ("The result is a tie!")
}else if (choice1 === "ROCK" && choice2 === "PAPER"){
return("The computer chose:" + computerChoice + ". You lose");
}else if (choice1 === "ROCK" && choice2 === "SCISSORS"){
return("The computer chose:" + choice2 + ". You win!");
}else if (choice1 === "PAPER" && choice2 === "ROCK"){
return("The computer chose:" + choice2 + ". You lose.");
} else if (choice1 === "PAPER" && choice2 === "SCISSORS"){
return("The computer chose:" + choice2 + ". You lose.");
} else if (choice1 === "SCISSORS" && choice2 === "ROCK"){
return("The computer chose:" + choice2 + ". You lose.");
} else if (choice1 === "SCISSORS" && choice2 === "PAPER"){
return("The computer chose:" + computerChoice + ". You win!");
} else {
return("You entered an invalid input");
}
}
document.write("User choice: " + userChoice);
document.write("Computer choice: " + computerChoice);
document.getElementById("rps").innerHTML = compare(userChoice, computerChoice);
<p id="rps"></p>
:)
看来我下面的提示没有出现。我无法让这段代码工作。我仍然是一名初学者,但我已经编码了大约 3 个月了。
<html>
<title>Random Code</title>
<head>
<style>
body {
background-color: green;
color: white;
}
</style>
<script>
var userChoice = prompt("Choose Rock Paper or Scissor!").toUpperCase();
//this prompt is not showing up.
var computerChoice = Math.random();
if (computerChoice < .34) {
computerChoice = "ROCK";
} else if (computerChoice > .33 && computerChoice <= .67) {
computerChoice = "PAPER";
} else {
computerChoice = "SCISSORS";
}
document.write("Computer: " + computerChoice);
var compare = function (choice1, choice2) {
if (choice1 === choice2) {
return ("The result is a tie!")
} else if (choice1 === "ROCK" && choice2 === "PAPER") {
return ("The computer chose:" + computerChoice + ". You lose");
} else if (choice1 === "ROCK" && choice2 === "SCISSORS") {
return ("The computer chose:" + choice2 + ". You win!");
} else if (choice1 === "PAPER" && choice2 === "ROCK") {
return ("The computer chose:" + choice2 + ". You lose.");
} else if (choice1 === "PAPER" && choice2 === "SCISSORS") {
return ("The computer chose:" + choice2 + ". You lose.");
} else if (choice1 === "SCISSORS" && choice2 === "ROCK") {
return ("The computer chose:" + choice2 + ". You lose.");
} else if (choice1 === "SCISSORS" && choice2 === "PAPER") {
return ("The computer chose:" + computerChoice + ". You win!");
} else {
return ("You entered an invalid input");
}
}
document.write("User choice: " + userChoice);
document.write("Computer choice: " + computer Choice);
document.getElementById("rps").innerHTML = compare(userChoice, computerChoice);
</script>
</head>
<body>
<p id="rps"></p>
</body>
</html>
如果您有任何指点或建议,我将永远感激不已!
这听起来可能很愚蠢,但您是否选中了提示 'prevent this page from creating additional dialogues' 中的框。在隐身页面中试用您的应用。
行
document.write("Computer choice: " + computer Choice);
应该是
document.write("Computer choice: " + computerChoice);
您还应该移动页面底部的脚本。
<html>
<title>Random Code</title>
<head>
<style>
body {
background-color: green;
color: white;
}
</style>
</head>
<body>
<p id="rps"></p>
<script>
var userChoice = prompt("Choose Rock Paper or Scissor!").toUpperCase();
//this prompt is not showing up.
var computerChoice = Math.random();
if (computerChoice < .34) {
computerChoice = "ROCK";
} else if (computerChoice > .33 && computerChoice <= .67) {
computerChoice = "PAPER";
} else {
computerChoice = "SCISSORS";
}
document.write("Computer: " + computerChoice);
var compare = function(choice1, choice2) {
if (choice1 === choice2) {
return ("The result is a tie!")
} else if (choice1 === "ROCK" && choice2 === "PAPER") {
return ("The computer chose:" + computerChoice + ". You lose");
} else if (choice1 === "ROCK" && choice2 === "SCISSORS") {
return ("The computer chose:" + choice2 + ". You win!");
} else if (choice1 === "PAPER" && choice2 === "ROCK") {
return ("The computer chose:" + choice2 + ". You lose.");
} else if (choice1 === "PAPER" && choice2 === "SCISSORS") {
return ("The computer chose:" + choice2 + ". You lose.");
} else if (choice1 === "SCISSORS" && choice2 === "ROCK") {
return ("The computer chose:" + choice2 + ". You lose.");
} else if (choice1 === "SCISSORS" && choice2 === "PAPER") {
return ("The computer chose:" + computerChoice + ". You win!");
} else {
return ("You entered an invalid input");
}
}
document.write("User choice: " + userChoice);
document.write("Computer choice: " + computerChoice);
document.getElementById("rps").innerHTML = compare(userChoice, computerChoice);
</script>
</body>
</html>
当我 运行 你在 jsfiddle 中的代码并注释掉除第一个之外的所有内容时,它工作正常。 "fiddling" 之后我发现了你的错误。第 34 行有
document.write("Computer choice: " + computer Choice);
而不是
document.write("Computer choice: " + computerChoice);
var userChoice = prompt("Choose Rock Paper or Scissor!", "rps").toUpperCase();
//this prompt is not showing up.
var computerChoice = Math.random();
if (computerChoice < .34){
computerChoice = "ROCK";
} else if (computerChoice > .33 && computerChoice <= .67){
computerChoice = "PAPER";
}else{
computerChoice = "SCISSORS";
}document.write("Computer: " + computerChoice);
var compare = function(choice1, choice2){
if (choice1 === choice2){
return ("The result is a tie!")
}else if (choice1 === "ROCK" && choice2 === "PAPER"){
return("The computer chose:" + computerChoice + ". You lose");
}else if (choice1 === "ROCK" && choice2 === "SCISSORS"){
return("The computer chose:" + choice2 + ". You win!");
}else if (choice1 === "PAPER" && choice2 === "ROCK"){
return("The computer chose:" + choice2 + ". You lose.");
} else if (choice1 === "PAPER" && choice2 === "SCISSORS"){
return("The computer chose:" + choice2 + ". You lose.");
} else if (choice1 === "SCISSORS" && choice2 === "ROCK"){
return("The computer chose:" + choice2 + ". You lose.");
} else if (choice1 === "SCISSORS" && choice2 === "PAPER"){
return("The computer chose:" + computerChoice + ". You win!");
} else {
return("You entered an invalid input");
}
}
document.write("User choice: " + userChoice);
document.write("Computer choice: " + computerChoice);
document.getElementById("rps").innerHTML = compare(userChoice, computerChoice);
<p id="rps"></p>
:)