Javascript 语法错误:意外的令牌错误
我在这里得到一个语法错误,但不明白为什么。短暂性脑缺血发作Javascript 语法错误:意外的令牌错误,javascript,Javascript,我在这里得到一个语法错误,但不明白为什么。短暂性脑缺血发作 var userChoice = prompt("Do you choose rock, paper or scissors?"); var computerChoice = Math.random(); console.log(computerChoice); if(computerChoice >= 0.33) { computerChoice === "rock"; } else if ( computerChoi
var userChoice = prompt("Do you choose rock, paper or scissors?");
var computerChoice = Math.random();
console.log(computerChoice);
if(computerChoice >= 0.33) {
computerChoice === "rock";
} else if ( computerChoice >= 0.34 && <= 0.66){
computerChoice === "paper";
} else (computerChoice >= 0.67 && <= 1) {
computerChoice === "scissors";
}
var userChoice=prompt(“您选择石头、布还是剪刀?”);
var computerChoice=Math.random();
console.log(计算机选择);
如果(计算机选择>=0.33){
computerChoice==“rock”;
}否则如果(computerChoice>=0.34&&=0.67&&Hmm,这里有几个问题
语法上:
} else ( computerChoice >= 0.67 && <= 1 ) {
但是在条件块中执行的东西实际上并没有做任何事情。你只是在测试一些东西是否相等,然后忽略测试结果
我想你想要的是:
var userChoice = prompt("Do you choose rock, paper or scissors?");
var computerChoice = Math.random();
console.log(computerChoice);
if ( computerChoice <= 0.33 ) {
computerChoice = "rock";
} else if ( computerChoice >= 0.34 && computerChoice <= 0.66 ) {
computerChoice = "paper";
} else {
computerChoice = "scissors";
}
var userChoice=prompt(“您选择石头、布还是剪刀?”);
var computerChoice=Math.random();
console.log(计算机选择);
如果(computerChoice=0.34&&computerChoice第二次逻辑比较缺少变量名(computerChoice
),代码最后部分缺少else
,而不是elseif
。此外,在应该使用赋值的点使用类型/值比较
var userChoice = prompt("Do you choose rock, paper or scissors?");
var computerChoice = Math.random();
console.log(computerChoice);
if(computerChoice >= 0.33) {
computerChoice = "rock";
} else if ( computerChoice >= 0.34 && computerChoice <= 0.66){
computerChoice = "paper";
} else {
computerChoice = "scissors";
}
var userChoice=prompt(“您选择石头、布还是剪刀?”);
var computerChoice=Math.random();
console.log(计算机选择);
如果(计算机选择>=0.33){
computerChoice=“rock”;
}否则,如果(computerChoice>=0.34&&computerChoice)出现了什么错误…控制台日志显示了什么?您仍然使用比较而不是赋值。一整天都在发生一些事情,似乎只保留了选择编辑:/谢谢,更正了代码。
var userChoice = prompt("Do you choose rock, paper or scissors?");
var computerChoice = Math.random();
console.log(computerChoice);
if ( computerChoice <= 0.33 ) {
computerChoice = "rock";
} else if ( computerChoice >= 0.34 && computerChoice <= 0.66 ) {
computerChoice = "paper";
} else {
computerChoice = "scissors";
}
var userChoice = prompt("Do you choose rock, paper or scissors?");
var computerChoice = Math.random();
console.log(computerChoice);
if(computerChoice >= 0.33) {
computerChoice = "rock";
} else if ( computerChoice >= 0.34 && computerChoice <= 0.66){
computerChoice = "paper";
} else {
computerChoice = "scissors";
}