I understand that the parameter in this exercise is holding a value that is a string. I have tried these solutions:
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!"');
What I do not understand is how to pull the value out of the parameter. All of the tutorials that I have found have multiple parameters.
Here is the original exercise though:
Modify the function to return the given string with an exclamation mark added to the end of it.
function addingGrace(s) {
}
/* Do not modify code below this line */
console.log(addingGrace('only the beginning'), '<-- should be "only the beginning!"');
Does anyone know where I can find a resource that references this type of work with single value parameters. I do not want the answer to this particular exercise as it is for an entrance exam for a coding school. I really wanted to figure this out myself but I am stuck.
You just need to return the parameter s
which holds the value only the beginning
.
Please see code snippet.
function addingGrace(s) { return s +"!"; } /* Do not modify code below this line */ console.log(addingGrace('only the beginning'), '<-- should be "only the beginning!"');
You can just use backticks (template literals/strings). You also need to return
from the function:
function addingGrace(s) { return `"${s}"`; } console.log(addingGrace('only the beginning'));
function addingGrace(s) { return (s + '!') } console.log(addingGrace('only the beginning'))
The code:
function addingGrace(s) {
console.log ("'only the beginning!'");
}
does not work because the code is already logging your request instead of returning the text you add.
You probaly would want to do is this:
function addingGrace(s) {
return(s);
}
But because the exercise wanted the text to have an exclamation point do this:
function addingGrace(s) {
return(s + "!");
}
I hope I helped!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.