Apply Functional Programming to Convert Strings

Hello, i cant understand why didnt my code pass tests. Can you help me understand)

/ the global variable
var globalTitle = “Winter Is Coming”;

// Add your code below this line
function urlSlug(title) {
var arr=title.split(/\s+/);
for (let i=0;i<arr.length;i++) {
return arr.join("-");

// Add your code above this line

var winterComing = urlSlug(globalTitle); // Should be “winter-is-coming”

Hi @Timazver

It’s because your failing the test case:

urlSlug(" Winter Is Coming") should return "winter-is-coming".

Also, you should really be using functional programming to solve this challenge, reduce, map, filter etc…

Thank you for your reply. But i execute my code in my PC and it works good)