How to display results after running the code

I need to display the results after running my code. Purpose is to catch the error. Console.log command won’t display no matter where I place it.
I therefore know that code does not pass certain element of the test, but don’t know why.
How to display results after running my code?
Many thanks.

Your code so far


// The global variable
var globalTitle = "Winter Is Coming";

// Only change code below this line

function urlSlug(title) {

return title
.toLowerCase()
.split(/\s+/g)
.join('-')

//Where to place console.log command to see the results?
}


// Only change code above this line

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36.

Challenge: Apply Functional Programming to Convert Strings to URL Slugs

Link to the challenge:

What you can do is create an intermediate variable to hold the result you want to return and then sent that to console.log before returning it.

function urlSlug(title) {
  let result = title
    .toLowerCase()
    .split(/\s+/g)
    .join('-');
  console.log(result);
  return result;
}
1 Like

By the way, I believe the g flag is not necessary here. Split is always iterative.

1 Like

Another strategy along with the one previously mentioned is to store the return value:

function name(){
blah...
}
let result = name()
console.log(result)

As a hint for the exercise, pass

"    hey this string"

and check what happens with the result.

1 Like

Yes, it works! Thanx.

Yeap…spaces at the beginning of the string. After split, first element is a space, hyphenated with the rest of the crew, I get “-winter-is-coming”. :sweat_smile: