Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/39.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/wix/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 语法错误:意外的令牌错误_Javascript - Fatal编程技术网

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";
}