Can anyone please help me? I'm stuck on Javascript Word Blanks Exercise

I have no idea what it’s asking me to do. I’m new to Javascript and I haven’t come across a lesson here that explains “function” or “result”. So, I’m not sure what it’s asking me to do. Help!

Hi there :slight_smile:
A function is a module type thing that you can declare, and then later use whenever you’d like!
So in this case they have outlined a function for you called “wordBlanks” and it has 4 “parameters” (code line 2).
Which just means, when you call the function, you will also tell it those 4 parameters to use within itself.

Observe line 12. This is where you are calling the function. When you call it, you are sending in those 4 strings as the parameters. i.e. myNoun = “dog”, etc.

Now within the function you will want to save to your string data type variable “result”, the string you would like to be returned when you call the function.
How this works is when you call the function, it executes and then returns something if you tell it to. In this case you will be returning the variable “result” after you change it.

Sorry this is prolly lengthy and confusing. It’s my first time trying to help someone on here. And also when I look up the Word Blanks problem. It shows my solution I did long ago. So I’m not sure what exactly you’re looking at (what was provided).

7 Likes

When you find yourself confused while trying to come up with a solution on FreeCodeCamp. It can be really beneficial to read what your expected output is suppose to be for different inputs (on the bottom left of the screen). And if you don’t understand why a particular input it failing. Manually type that in in your code and then observe on the console.log what output you are instead getting. It’s much more helpful to know, not just that your output is currently wrong, but what it is exactly. Because then you can understand what you are doing wrong and fix it! :slight_smile:

Ideally as you write programs. You want to constantly be testing it as you go and not just write the entire program and then cross your fingers and test it. :stuck_out_tongue: Just a tip! Cheers

2 Likes

Thank you! I’m still kinda lost. Here’s what my screen shows:

function wordBlanks(myNoun, myAdjective, myVerb, myAdverb) {
var result = “”;
// Your code below this line

// Your code above this line
return result;
}

// Change the words here to test your function
wordBlanks(“dog”, “big”, “ran”, “quickly”);

It’s also asking me to change the words. I just can’t seem to figure it out. Whatever it tells me I’m doing wrong is going over my head. =(

I don’t even know where I’m supposed to be typing in answers. lol.

Hey man. Sorry I’m out having dinner and a couple beers :stuck_out_tongue:
Well do you see where is says “//type your code below here…” or “above here”.
That’s where you type your code :smiley:

Just type this:

result = “test test 123” + myNoun + “abc123”;

And then hit run. And see what happens :stuck_out_tongue:

2 Likes

No worries! Hope you’re having a good time. Please don’t feel like you have to answer right away. I totally appreciate your help.

So, this is what it says when I type that in:

wordBlanks(“dog”, “big”, “ran”, “quickly”) should contain all of the passed in words separated by non-word characters (and any additional words in your madlib).
and
wordBlanks(“cat”, “little”, “hit”, “slowly”) should contain all of the passed in words separated by non-word characters (and any additional words in your madlib).

Haha it’s np man. I’m actually on my way home now. Not going too hard or anything. Too sleepy.
And these are popping up as email notifications when you respond so it’s not too difficult for me to respond :stuck_out_tongue:

But do me a favor and hit “run” or “go” or whatever again and look on the far left. You should see black box called a console.
It may have text on it somewhere that says “console.log”.

This is where it shows your output from your program. Tell me what you see when you run your program.

haha. ok.
here’s what it shows:
result = “test test 123” + myNoun + “abc123”;

:stuck_out_tongue: look again. It should say, exactly:
test test 123dogabc123

And my hope was, from you seeing the output. and knowing we typed
result = “test test 123” + myNoun + “abc123”;
You could understand what was happening. Observe how you pass dog as a parameter when you call the function. And then how you then use it within the function by calling… myNoun.

1 Like

I’m going to pass out soon and you’ll be on your own. But if it seems difficult, you are prolly just over thinking it. and maybe should take a break from it for a bit and come back to it tomorrow.
The solution to this problem only requires you to write a single line of code. Between those two //comment lines I mentioned earlier.

1 Like

awesome! i got passed it. Thanks! Happy New Year!

2 Likes

Haha awesome man! I knew it would click at some point. Happy new year man. Happy coding #cheers

1 Like

i got stuck on this one too and i know its an old topic but it came up in my search so im going to reply in case someone else is stuck and this comes up in their search.

when you run into issues look at the little console window under the line that says Reset Help Bug. by default on this challenge its just a black bar.

my first try at it looked like this:

function wordBlanks(myNoun, myAdjective, myVerb, myAdverb) {
var result = “”;
// Your code below this line

result = myNoun + myAdjective + myVerb + myAdverb;
// Your code above this line
return result;
}

// Change the words here to test your function
wordBlanks(“dog”, “big”, “ran”, “quickly”);

it failed but now looking at the black bar i could see that what it returned was: dogbigranquickly

in the instructions the second one says that it should return all of the passed in words SEPARATED BY NON-WORD CHARACTERS. so i changed the result = line to:

result = myNoun + " " + myAdjective + " " + myVerb + " " + myAdverb;

which is just adding a space between every word, now my output is: dog big ran quickly

which seems to pass the challenge.

hope this helps anyone else who stumbles here

-MC

4 Likes

I also had issues with this challenge. My issue was I didn’t understand I needed to to use result =. I was trying var, return and function.

mcockrell1, your last solution does pass the challenge but the idea was you would put your own flair on it. So instead of reading just the answers it reads like "I love my big dog. He ran quickly down the street."
See Constructing Strings with Variables

1 Like

This is the correct way u surely got result

function wordBlanks(myNoun, myAdjective, myVerb, myAdverb)
{
var result = “”;
// Your code below this line
var a=“dog”;
var b=" big ";
var c="ran ";
var d="quickly ";

var e="cat ";
var f="little ";
var g="hit ";
var h=“slowly”;
var wordBlanks= a+ b+ c+ d+ e+ f+ g +h;
result=wordBlanks;

//word Your code above this line
return result;
}

// Change the words here to test your function
wordBlanks(“dog”, “big”, “ran”, “quickly” + “cat”, “little”, “hit”, “slowly”);

@CraftyClark Thanks for replying while you were out and helping out @cbgz68. If you’re ever in Seattle, first drink on me! I really appreciate people helping out with clear answers that still help you figure it out yourself.

Just an update as well: I was stuck here as well but read this and realized using result prints out your string, is my understanding. That was what I was missing (that and spaces. Make sure to add them!).

1 Like

Haha omg dude this thread helped me so much - I feel so stupid I was trying to define the var result rather than call the function!

Who knows the best way to learn js

Hi, I’ve had that same problem. So far the best I’ve found to get some experience on the basics is Udacity free Intro to JavaScript and JavaScript basics. There is also a Wes Bos JavaScript course, I’ve seen and signed up for, but I have not started yet. I hope this helps :smile: