wordBlanks JS Challenge Help

I already tried every combination and can’t make the tests pass. Even the solution found on the forum post about the exercise gives me the exact same error. How is that even possible?

Forum post: freeCodeCamp Challenge Guide: Word Blanks

1 Like

I copied the solution exactly and it works for me. What error messages are you getting?

I get this error:

You should not directly use the values “dog”, “ran”, “big”, or “quickly” to create wordBlanks.

1 Like

Can I see your updated code?

My entire code:

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

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

The code you have shared works on my end. Please ensure that you have disabled any extensions that interface with the freeCodeCamp website (such as Dark Mode and Ad Blocker), and set your browser zoom level to 100%. Both of these factors can cause tests to fail erroneously.

Also, if your browser isn’t updated that might be affecting the test. I don’t know what browser you are using right now but it is working for me on google chrome.

Tried in Firefox and the test indeed passed. I was using Chrome, and even with all the extensions disabled the test were failing.

Glad I could get this sorted. Thanks for the help.

2 Likes

I already solved the issue by switching browsers. The exercise was giving errors on Chrome and working on Firefox with the same exact code. So there’s no issue with spaces.

I did this and it worked:

REDACTED

In my other prep course we are logging to Replit so I recalled the console.log , tried it and it worked.

It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge.

1 Like

My apologies! I’m very new. I will edit it down to suggestions :slight_smile:

hi , i wanna share my solution , i think could be more easy to understand when you are learning and I have tried to following the exercises instructions .
let me know if you like it . :grinning:
cheers

/////// wordBlanks ////
var myNoun = "dog";

var myAdjective = "big";

var myVerb = "ran";

var myAdverb = "quickly";

// Only change code below this line

var wordBlanks = " "; // Change this line

// Only change code above this line

function wordBlank(n1,n2,n3,n4){

 wordBlanks = 'the ' + "will change " + n1 + " " + n2 + " " + n3 + " " + n4;

 var result = wordBlanks;

 return result;

}

wordBlank(myNoun,myAdjective,myVerb,myAdverb);

console.log(wordBlank(myNoun,myAdjective,myVerb,myAdverb));

I have added spoiler tags to your solutions for those who have not worked on this problem.

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 (’).

Hi @josepedrolorenzini !

Welcome to the forum!

For this approach for using a function, you could simplify it by just returning wordblanks instead of creating the extra variable of result.

function wordBlank(n1,n2,n3,n4){

 return wordBlanks = 'the ' + "will change " + n1 + " " + n2 + " " + n3 + " " + n4;

}

You could also simplify even more using es6 arrow functions and template literals.

var wordBlanks; // Change this line

// Only change code above this line

const wordBlank = (n1,n2,n3,n4) => wordBlanks = `the will change ${n1} ${n2} ${n3} ${n4}` ;


console.log(wordBlank(myNoun,myAdjective,myVerb,myAdverb));

I don’t see how this challenge is at all a ‘gotca’. The instructions are very clear.

In this challenge, we provide you with a noun, a verb, an adjective and an adverb. You need to form a complete sentence using words of your choice, along with the words we provide.

You will need to use the string concatenation operator + to build a new string, using the provided variables: myNoun , myAdjective , myVerb , and myAdverb . You will then assign the formed string to the wordBlanks variable. You should not change the words assigned to the variables.

You will also need to account for spaces in your string, so that the final sentence has spaces between all the words. The result should be a complete sentence.

The example shows string concatination. The challenges asks you do do string concatination with variables. Zero 'gotcha’s.

The conversation is very clear about the fact that the original solution given by OP works just fine, so I am confused by your commentary.

Hi @anon74497334 !

I am not sure what you are referring to here.
The OP’s code passed the test.
The issue was that they had an extension that interfered with the test result.

The example teaches you about string concatenation.

var sentence = "It was really " + "hot" + ", and we " + "laughed" + " ourselves " + "silly" + ".";

That’s the real lesson.
The challenge wants you to concatenate with variables.

I actually disagree with this.
Learning how to think like a programmer early on is important to becoming a strong one.
I don’t see any benefit in waiting until later.
Learning how to think in a analytic mindset takes time and practice.
So it is best to learn it early.


The goal of the FCC curriculum is not to intentionally trick people.
FCC is open source which means that anyone can look at their entire curriculum and make suggestions for improvement.
FCC wants to help people learn how to code and wants to improve.

But there is no ulterior motive to intentional deceive people during the learning process.

I’ve read the challenge.

The sample solution contains “all of the words assigned to the variables myNoun , myVerb , myAdjective and myAdverb separated by non-word characters (and any additional words in your madlib).”

Zero gotchas.

And even if you somehow object to this solution, alternate solutions containing other words are also marked as valid by the test suite, such as the original solution in this post.

1 Like

I agree with @JeremyLT that the official solution does meet the requirements.

But also, just to reiterate, the OP’s solution was correct.

wordBlanks += "The " + myNoun + " was so " + myAdjective + " that we " + myVerb + " "  + myAdverb + ".";

I am still confused why you are upset.
FCC is not trying to deceive people or be intellectually dishonest.

1 Like

I agree that an example like this would illustrate the situation better:

var adjective = "hot";

var sentence = "It was really " + adjective + ", and we " + "laughed" + " ourselves " + "silly" + ".";

However,:

You could also say that it’s a clear indication that people don’t actually read the description, they only scan the examples and try to solve the challenge through pattern-matching instead of understanding the information that is given to them. Surely the latter takes longer and requires the ability to read through instructions and being able to convert them to code without having an easy-to-replicate solution template.

In my opinion, there are already a lot of challenges with template-solutions (the section on object-oriented JavaScript can basically be solved entirely by copy-pasting the example and changing some variable names), and I must say that I remember walking through that section extremely quickly and learning extremely little in the process.

2 Likes