const wordBlanks = (myNoun, myAdjective, myVerb, myAdverb);{
console.log(wordBlanks ("dog", "big", "ran", "quickly"));
}
const result = "The " myAdjective "" myNoun "" myVerb "" "to the store" myAdverb;
It says ReferenceError: myNoun is not defined. But I defined it, it's the dog.
Given:
const myNoun = "dog";
const myAdjective = "big";
const myVerb = "ran";
const myAdverb = "quickly";
// Only change code below this line
const wordBlanks = ""; // Change this line
// Only change code above this line
CodePudding user response:
Here is the proper arrow function syntax using a template string:
const wordBlanks = (myNoun, myAdjective, myVerb, myAdverb) =>
`The ${myAdjective} ${myNoun} ${myVerb} to the store ${myAdverb}`;
console.log(wordBlanks('dev', 'lazy', 'coded', 'efficiently'));
CodePudding user response:
Your syntax is all messed up .. Your return (which you defined) is OUTSIDE the function .. And you never CALL the function ..
function wordBlanks(myNoun, myAdjective, myVerb, myAdverb) {
const result = "The " myAdjective " " myNoun " " myVerb " " " to the store " myAdverb;
return result;
}
console.log(wordBlanks("dog", "big", "ran", "quickly"));
UPDATE
And as @EssXTee has suggested .. This is a great situation to be using interpolation. IE
function wordBlanks(myNoun, myAdjective, myVerb, myAdverb) {
const result = `The ${myAdjective} ${myNoun} ${myVerb} to the store ${myAdverb}`;
return result;
}
console.log(wordBlanks("dog", "big", "ran", "quickly"));
SECOND UPDATE BASED ON OP EDIT
const myNoun = "dog";
const myAdjective = "big";
const myVerb = "ran";
const myAdverb = "quickly";
// Only change code below this line
const wordBlanks = `The ${myAdjective} ${myNoun} ${myVerb} Into the Lake ${myAdverb}`; // Change this line
// Only change code above this line
console.log(wordBlanks);
CodePudding user response:
I assume you wanted to write a function wordBlanks that builds the given parameters into a sentence. like that:
function wordBlanks (myNoun, myAdjective, myVerb, myAdverb) {
return `The ${myAdjective} ${myNoun} ${myVerb} to the store ${myAdverb}`;
}
const res = wordBlanks ("dog", "big", "ran", "quickly");
console.log(res)