You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Pluralsight作业代码功能正常但评分失败求助(第13行问题)

解决Pluralsight作业第13行未完成提示问题

你的代码能实现基础功能,但Pluralsight的评分系统是严格匹配要求格式+代码规范来判定的,第13行的提示对应输出格式、代码写法的问题,具体修正点如下:

核心问题1:输出字符串完全不匹配要求格式

要求的标准输出是:

Hello Tom. Your age is 39. The year you were born is 1983

你的代码生成的字符串存在3处关键差异:

  • 缺少句点分隔:Hello name、your age is age后均无.
  • 大小写错误:your需改为Your
  • 介词错误:born in要改成born is,同时多余的空格要去掉

核心问题2:不必要的eval使用

eval(CURRENT_YEAR - age)属于冗余写法,直接计算CURRENT_YEAR - Number(age)即可。另外从input获取的age是字符串类型,显式转为数字能避免隐式转换的潜在问题。

次要问题:变量声明格式(可能影响评分)

虽然逗号分隔的let声明语法合法,但Pluralsight作业通常要求每个变量单独声明,提升代码可读性。


修改后的完整代码

function displayHello() {
  const CURRENT_YEAR = 2022;
  let name = document.getElementById("helloNameInput").value;
  let age = Number(document.getElementById("ageInput").value);

  // 严格匹配要求的输出格式
  document.getElementById("helloNameOutput").innerHTML = 
    `Hello ${name}. Your age is ${age}. The year you were born is ${CURRENT_YEAR - age}`;

  //To DO:
  //Assign the current year to a constant named CURRENT_YEAR.
  //Assign the name entered in the helloNameInput text box to a variable named name.
  //Assign the age entered in the ageInput text box to a variable named age.
  //Use CURRENT_YEAR, name & age to assign the following string to the header 2 (h2) tag named helloNameOutput:
  //Hello Tom. Your age is 39. The year you were born is 1983
  //Please note that this is the output if the name of Tom and age of 39 is entered by the user.
}

function clearName() {
  document.getElementById("helloNameOutput").innerHTML = "";
  document.getElementById("helloNameInput").value = "";
  document.getElementById("ageInput").value = "";
  //To Do:
  //Clear the string in the helloNameInput text box
  //Clear the string in the ageInput text box
}

修改说明

  1. 将age转为数字类型,确保年份计算逻辑严谨
  2. 使用模板字符串拼接内容,更易对齐要求的格式
  3. 修正所有标点、空格、大小写问题,完全匹配标准输出
  4. 移除冗余的eval,直接执行算术运算
  5. 统一添加分号,符合基础代码规范

修改后Pluralsight的评分系统应该会识别到你已完成第13行的要求。

内容的提问来源于stack exchange,提问作者nightowl898

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.13 12:50:21