首页 > 解决方案 > 如何在 JavaScript 中引用或提取单个值参数?

问题描述

我知道本练习中的参数是一个字符串值。我尝试了这些解决方案:

function addingGrace(s) {
console.log ("'only the beginning!'");

}

/* Do not modify code below this line */

console.log(addingGrace('only the beginning'), '<-- should be "only the beginning!"');

我不明白的是如何从参数中提取值。我发现的所有教程都有多个参数。

这是原始练习:

修改函数以返回给定字符串,并在其末尾添加感叹号。

function addingGrace(s) {

}

/* Do not modify code below this line */

console.log(addingGrace('only the beginning'), '<-- should be "only the beginning!"');

有谁知道我在哪里可以找到使用单值参数引用此类工作的资源。我不想要这个特定练习的答案,因为它是针对编码学校的入学考试的。我真的很想自己解决这个问题,但我被困住了。

标签: javascriptstringfunction

解决方案


您只需要返回s包含 value的参数only the beginning

请参阅代码片段。

function addingGrace(s) {
    return s +"!";
}

/* Do not modify code below this line */

console.log(addingGrace('only the beginning'), '<-- should be "only the beginning!"');


推荐阅读