javascript - 语法错误 : expected expression, 获取关键字 'else'

标签 javascript

我正在练习一些代码并遇到一些错误,任何人都可以帮助我。

显示错误,例如:

SyntaxError: expected expression, got keyword 'else'

下面是代码

var ageJohn = 25;
var heightJohn = 165;

var ageSmith = 60;
var heightSmith = 180;

var ageMalli = 24;
var heightMalli = 170;

var scoreJohn = heightJohn + 5 * ageJohn;
var scoreSmith = heightSmith + 5 * ageSmith;
var scoreMalli = heightMalli + 5 * ageMalli;


if (scoreJohn > scoreSmith && scoreJohn > scoreMalli); {
    console.log('John wins with ' + scoreJohn);
} else if (scoreSmith > scoreJohn && scoreSmith > scoreMalli); {
    console.log('Smith wins with! ' + scoreSmith);
} else(scoreMalli > scoreJohn && scoreMalli > scoreSmith); {
    console('Mary wins with ' + scoreMalli);
}

最佳答案

您还有一个额外的;。错误在这里:

} else if (scoreSmith > scoreJohn && scoreSmith > scoreMalli); {

更改为

} else if (scoreSmith > scoreJohn && scoreSmith > scoreMalli) {

另外两行如果有类似问题

关于javascript - 语法错误 : expected expression, 获取关键字 'else',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45419116/

相关文章:

javascript - 如何使用 Javascript 获取 'css-pixel'(媒体查询)宽度?

javascript - 持续时间的正则表达式

javascript - D3 通过 json 文件可视化网络数据(节点和链接)

javascript - 将分类数据的配色方案与线性范围相结合

javascript - 从第一个数组中删除重复的索引值,按照第一个操作第二个(在某些特定条件下)

javascript - 在 Linux 上使用 Electron 安装依赖项

javascript - 如何在 Javascript 中的两种 RGB 颜色之间转换?

Javascript 变量恢复为原始变量

javascript - 如何在jquery html应用程序中使用wcf服务作为远程或本地?

javascript - Uncaught ReferenceError : (function) is not defined