【问题标题】:Why does setting a new value to a variable not reflect in console? [closed]为什么为变量设置新值不会反映在控制台中? [关闭]
【发布时间】:2020-07-11 18:57:13
【问题描述】:

正在阅读 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

标签: javascript console


【解决方案1】:

examReport 已经在上一行进行了评估。

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

【讨论】:

  • @CheckeredBurrito,我不知道在封闭式问题中是否可以这样做,但如果可能,请接受我的回答(绿色勾号)。谢谢你:)
猜你喜欢
  • 1970-01-01
  • 2021-04-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-22
  • 2016-06-19
  • 2022-11-21
相关资源
最近更新 更多