为什么为变量设置新值不会反映在控制台中?
Why does setting a new value to a variable not reflect in console?
正在阅读 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.' }`;
it returns "You scored 45/70 (64%). Bad luck, you didn't pass this time."
当我将新值设置为 examScore
时,return 不反映新值。
我为 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
,它 returns 60
。
不确定它是开发人员控制台还是 js 问题。任何指导将不胜感激!
examReport
已在上一行中计算过。
您需要将其重新设置为新的模板字符串,它才会起作用。
正在阅读 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.' }`;
it returns "You scored 45/70 (64%). Bad luck, you didn't pass this time."
当我将新值设置为 examScore
时,return 不反映新值。
我为 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
,它 returns 60
。
不确定它是开发人员控制台还是 js 问题。任何指导将不胜感激!
examReport
已在上一行中计算过。
您需要将其重新设置为新的模板字符串,它才会起作用。