尝试使用 for...in 循环并添加一个 if/else 语句并一直说我缺少一个“)”
Trying to use for...in loop and adding an if/else statement and keeps saying i am missing a ")"
const testScores = {
John : 99,
Jess : 78,
Ryan : 89,
Tom : 62,
Jane: 57,
Ben: 83
};
for (person in testScores){
if (testScores[person] > 90){
console.log("Well done "+ person ". You scored " + testScores[person])
};
else{
console.log(person + " scored " + testScores[person])};
}
- 首先是打字错误,您忘记在
person
和". You scored "
之间添加+
- 其次你在 if 块之后使用
;
,因此,它的程序没有编译。
const testScores = {
John: 99,
Jess: 78,
Ryan: 89,
Tom: 62,
Jane: 57,
Ben: 83
};
for (person in testScores) {
if (testScores[person] > 90) {
console.log("Well done " + person + ". You scored " + testScores[person]);
} else {
console.log(person + " scored " + testScores[person]);
}
}
const testScores = {
John : 99,
Jess : 78,
Ryan : 89,
Tom : 62,
Jane: 57,
Ben: 83
};
for (person in testScores){
if (testScores[person] > 90){
console.log("Well done "+ person ". You scored " + testScores[person])
};
else{
console.log(person + " scored " + testScores[person])};
}
- 首先是打字错误,您忘记在
person
和". You scored "
之间添加 - 其次你在 if 块之后使用
;
,因此,它的程序没有编译。
+
const testScores = {
John: 99,
Jess: 78,
Ryan: 89,
Tom: 62,
Jane: 57,
Ben: 83
};
for (person in testScores) {
if (testScores[person] > 90) {
console.log("Well done " + person + ". You scored " + testScores[person]);
} else {
console.log(person + " scored " + testScores[person]);
}
}