Using consol.log


why when i run this script in my browser, i get in the console the code function, instead of " i ran with my stinky dog"?

Hi @tomer-n, if you are getting the function instead of a string, perhaps you omitted the parenthesis () after the function inside the console.log statement. Maybe this is why you are printing the actual function instead of running the function and getting its output.

EDIT: after the script image loaded, yes, I notice in you console.log(wordBlanks) you are not using parenthesis, which is causing to print the function itself instead of running the function.

You should write console.log(wordBlanks("dog", "stincky", "ran", "quickly")) if you want to get this output.This will execute the function with your input, then return the string you are looking for and print it to the console.

NOTE: if you just want to print this output, you can delete the line above the console.log, or you can assign that line to a variable and use that variable inside the parenthesis of console.log.

Hope it helps!

1 Like

hey @TefiC that worked thanks. one thing i dont understand is, if i declered already that

wordBlanks(“dog”, “stinky”, “ran”, “quickly”);

why do i need to enter it also in the console.log?

Because when you declare wordBlanks("dog", "stinky", "ran", "quickly");, you will execute the function and that function will return a string, but since you are not assigning the string to a variable, it’s lost, you can’t use it anymore.

If instead, you write this:

var myString = wordBlanks("dog", "stincky", "ran", "quickly")


The string returned by calling the function wordBlanks() is stored in the variable myString so you can then use it in your code, like in console.log(myString).

This happens because you have a return statement in your function. If instead you had the console.log() statement inside the function, it would automatically print the string whenever you call it, without the need to save it to a variable for later use.

Please let me know if this clarifies you doubt. :slight_smile:

1 Like

your answer is very accurate, thanks for the help!