Javascript madlibs assignment

Tell us what’s happening:
Hi pals,

I need some help understanding why this simple code will not execute properly. I ran it in Vscode with quokka and it checks out. If I use the actually variable assignments there is an error not to use the actual words and if I do not use them then I get the last unchecked tasks which is to use all variable assignments. All help is much appreciated. Thanks.

Your code so far
const wordBlanks = “‘The ’ + ‘myAdjective’ + ’ myNoun’ + ‘myVerb’ + 'myAdverb ’ + ‘.’”;

const myNoun = "dog";
const myAdjective = "big";
const myVerb = "ran";
const myAdverb = "quickly";

// Only change code below this line
const wordBlanks = "'The ' + 'myAdjective' + ' myNoun' + 'myVerb' + 'myAdverb ' + '.'"; // Change this line
// Only change code above this line

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36

Challenge: Word Blanks

Link to the challenge:

There are a few errors. If you print out your wordBlanks variable, you will see that it prints

'The ' + 'myAdjective' + ' myNoun' + 'myVerb' + 'myAdverb ' + '.'

You have wrapped the whole thing in double quotes, so it is going to print what is literally inside those quotes. Anything that is inside quotes is just a sequence of characters and will not be treated as code.

Thanks for the quick reply so, how would I allow the code to run? Please. If I cannot use the actual variable assignment names and I don’t want to print jus the variables but the values how can I do that. I don’t want to print “myAdjective” I want to print the value of “myAdjective” which is “big” etc.


1 Like

Hi @Kimchi622 !

Welcome to the forum!

You don’t want to include strings around the variable names.
Here is an example of what you are supposed to do.

Run this example code

const firstName = 'Jessica';
const job = 'freeCodeCamp'
console.log(firstName + ' is awesome and works at ' + job + '.')

Study that example and apply that same logic to the challenge.
You don’t need to create any variables in your case, but hopefully the basic idea makes sense.
Be careful of spaces.

Hope that helps!

1 Like

Hi! Cool thanks I did that but now I’m stuck on spaces because with words that I have added they are not strings already so I can wrap them and create a string and then add a space with in but for the variables that have been assigned a value I cannot wrap or else the literal variable will print out and that isn’t what I want and so I am befuddled as to how I can add spaces without being in a string and yes I tried just adding an extra space next to the variable and that didn’t work. Lol

Its really hard for us to give more assistance without your updated code.

const wordBlanks = "The " + myAdjective + myNoun + myVerb + myAdverb + ".";

prints---- “The bigdogranquickly.”

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

Why not use a space inside of a string? You can make a string with just a space inside it.

As said, you can add the space as a string between the variables.

An example, just in case it isn’t clear:

const firstName = "John";
const lastName = "Doe";
const fullName = firstName + " " + lastName;

console.log(fullName); // John Doe

I tried that and it returns the same. You mean like this correct? “The” + “ “ + myAdjective ‘’’ should return “The big” and so on but it doesn’t.

Please show your full code instead of this fragment. I think something is missing in the code you shared.

Ok it worked. I had two spaces that is why I couldn’t see it at first. I put a space after the and then after the again and I thought it was only the one space. Like “The “ + “ “ +


This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.