
FreeCodeCamp JavaScript 挑战步骤 46 审核失败原因及解决方案
在 FreeCodeCamp 的 JavaScript 挑战中,部分代码未能通过审核,问题在于缺少进入商店的提示信息。
原始代码 (审核失败):
<code class="javascript">function gostore() {
button1.innertext = "buy 10 health (10 gold)";
button2.innertext = "buy weapon (30 gold)";
button3.innertext = "go to town square";
button1.onclick = buyhealth;
button2.onclick = buyweapon;
button3.onclick = gotown;
}</code>问题分析: 审核失败的原因是代码缺少对玩家进入商店行为的反馈。 FreeCodeCamp 的测试可能检查了是否正确显示了“You enter the store.” 这样的提示信息。
修改后的代码 (审核通过):
<code class="javascript">function goStore() {
text.innerText = 'You enter the store.'; // 添加进入商店提示
button1.innerText = "Buy 10 health (10 gold)";
button2.innerText = "Buy weapon (30 gold)";
button3.innerText = "Go to town square";
button1.onclick = buyHealth;
button2.onclick = buyWeapon;
button3.onclick = goTown;
}</code>关键修改: 在 goStore 函数的开头添加了 text.innerText = 'You enter the store.'; 这行代码,向玩家显示进入商店的提示信息。 注意大小写变化,innerText 应该使用大写 I。 函数名也建议使用驼峰命名法 goStore。 确保 text 变量已正确定义并指向用于显示提示信息的元素。
通过添加这行代码,解决了审核失败的问题,程序能够正确地显示进入商店的提示信息,从而通过 FreeCodeCamp 的测试。
以上就是FreeCodeCamp步骤46审核失败:为什么我的商店代码需要添加进入商店提示?的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号