为什么为变量设置新值不能反映在控制台中



我正在学习MDN的教程,并希望扩展到我遇到这个问题的部分。当我运行以下代码时:

let examScore = 45;
let examHighestScore = 70;
examReport = `You scored ${ examScore }/${ examHighestScore } (${ Math.round((examScore/examHighestScore*100)) }%). ${ examScore >= 49 ? 'Well done, you passed!' : 'Bad luck, you didn't pass this time.' }`;

它返回"You scored 45/70 (64%). Bad luck, you didn't pass this time."当我将新值设置为examScore时,该返回不会反映新值。我为examScore设置了一个新值,然后再次运行examReport,如下所示。

examScore = 60;
examReport;

我期待着:

"You scored 60/70 (86%). Well done, you passed!"

我得到的是:

"You scored 45/70 (64%). Bad luck, you didn't pass this time."

我甚至检查了examScore,它返回60。不确定是开发人员控制台还是js问题。如有任何指导,我们将不胜感激!

examReport已经在前一行中进行了评估。

您需要再次将其设置为新的模板字符串,它就会工作。

最新更新