*Functional Programming: Apply Functional Programming to Convert Strings to URL Slugs

I am trying to console log my lines and it is not showing anything


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

// Only change code below this line

function urlSlug(title) {

let newTitle=globalTitle.slice(globalTitle.length)
console.log(newTitle)

let lowCaseTit=title.toLowerCase()
        
        for(let i=0;i<lowCaseTit.length;i++){
                   
                   if(lowCaseTit[i]=" "){

                     llowCaseTit.splice(i,1,"-")

                  console.log(lowCaseTitle);           
                   }
          
        }
}
// Only change code above this line

You need to try to run your function to see any output.

urlSlug(globalTitle)

When you do, you’ll see that you have a multitude of syntax issues.

1 Like

It is the same result.

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

// Only change code below this line

function urlSlug(globalTitle) {

let newTitle=globalTitle.slice(globalTitle.length)
console.log(newTitle)

let lowCaseTit=title.toLowerCase()
        
        for(let i=0;i<lowCaseTitle.length;i++){
                   
                   if(lowCaseTitle[i]=" "){

                     lowCaseTitle.splice(i,1,"-")

              //    console.log(lowCaseTitle);           
                   }
           return  
        }
}
// Only change code above this line

I mean that you need to try to run your function, not declare it with a different variable name.


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

// Only change code below this line

function urlSlug(title) {

let newTitle=globalTitle.slice(globalTitle.length)
console.log(newTitle)

let lowCaseTit=title.toLowerCase()
        
        for(let i=0;i<lowCaseTit.length;i++){
                   
                   if(lowCaseTit[i]=" "){

                     llowCaseTit.splice(i,1,"-")

                  console.log(lowCaseTitle);           
                   }
          
        }
}

urlSlug(globalTitle);
// Only change code above this line
1 Like

Thanks for your time!

1 Like

How may I update the value of newTitle?
1st Cycle= lowerCaseTitle[6].concat(hyphen). I get “winter-is coming”. Now, I want to use that result. How may I do it?

var globalTitle = "Winter Is Coming";

// Only change code below this line
function urlSlug(title) {
let lowerCaseTitle =title.toLowerCase()
let hyphen=("-");   
      //console.log(indexWhiteSpace)
    
         for (let i=0;i<lowerCaseTitle.length;i++){
                         //console.log(hyphen)
      if(lowerCaseTitle.indexOf(" ")>=0){
                  
  let newTitle =lowerCaseTitle[lowerCaseTitle.indexOf(" ")].concat(hyphen)  
                    
                    //console.log(newTitle)
             
             }
         

         }


}

console.log(urlSlug(globalTitle));
// Only change code above this line

It is done. Thanks!

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

// Only change code below this line
function urlSlug(title) {

 let newTitle= title.trim().split(/\s+/).join('-').toLowerCase();

 return newTitle
}

console.log(urlSlug(globalTitle));
// Only change code above this line
//title.split(/\s+/).join('-').toLowerCase().