我不明白为什么第12行出现语法错误,但似乎有一个。
g = 0
y = 0
c = 0
while(true) {
computer = random(3);
you = choose("Choose!", "Rock", "Paper", "Scissors");
if (computer == 1){
if (you == 2){
show("You win!");
g = g + 1;
y = y + 1;
if (g == 3) {
break;
show("Computer: " + c + "You: " + y);
}
} else if (you == 1) {
show("Draw");
g = g + 1;
if (g == 3) {
break;
show("Computer: " + c + "You: " + y;)
}
} else if (you == 3) {
show("Computer wins.");
g = g + 1;
c = c + 1;
if (g == 3) {
break;
show("Computer: " + c + "You: " + y;)
}
}
}
答案 0 :(得分:6)
y;)}
应该在y);}
两个地方
另一个问题,你在三个地方都有break; show(...
,show
我不认为会在break
之后运行
var g = 0,
y = 0,
c = 0;
while (true) {
computer = random(3);
you = choose("Choose!", "Rock", "Paper", "Scissors");
if (computer == 1) {
if (you == 2) {
show("You win!");
g = g + 1;
y = y + 1;
if (g == 3) {
break; // <=== break here?
show("Computer: " + c + "You: " + y);
}
} else if (you == 1) {
show("Draw");
g = g + 1;
if (g == 3) {
break; // <=== break here?
show("Computer: " + c + "You: " + y;) // <=== don't wink here ;)
}
} else if (you == 3) {
show("Computer wins.");
g = g + 1;
c = c + 1;
if (g == 3) {
break; // <==== break here?
show("Computer: " + c + "You: " + y;) // <=== don't wink here ;)
}
}
}
}
P.S。在发布
之前,我使用http://jsbeautifier.org/来美化我的代码答案 1 :(得分:2)
更容易看出你是否真的清理了代码。
g = 0
y = 0
c = 0
while (true) {
computer = random(3);
you = choose("Choose!", "Rock", "Paper", "Scissors");
if (computer == 1) {
if (you == 2) {
show("You win!");
g = g + 1;
y = y + 1;
if (g == 3) {
break;
show("Computer: " + c + "You: " + y);
}
} else if (you == 1) {
show("Draw");
g = g + 1;
if (g == 3) {
break;
show("Computer: " + c + "You: " + y;)
}
} else if (you == 3) {
show("Computer wins.");
g = g + 1;
c = c + 1;
if (g == 3) {
break;
show("Computer: " + c + "You: " + y;)
}
}
}
你有几个问题
show("Computer: " + c + "You: " + y;)
应为show("Computer: " + c + "You: " + y);
while
循环。random
,choose
和show
。break
。 (虽然不会导致任何错误,但很可能并非如此)答案 2 :(得分:0)
你最后错过了'}'。尝试beautify js缩进代码并使用jsHint发现错误。
答案 3 :(得分:-2)
可能是因为你在“休息”之后仍然有陈述;这是无法到达的。