Tell us what’s happening:
I have failed to pass the fourth case so far. In the solution 1 ( Solution) it used another filter function, but I don’t understand why is it used, and what it does. Thanks
Your code so far
// the global variable
var globalTitle = "Winter Is Coming";
// Add your code below this line
function urlSlug(title) {
return title.toLowerCase().split(/\s+/).join("-");
}
// Add your code above this line
var winterComing = urlSlug(globalTitle); // Should be "winter-is-coming"
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.117 Safari/537.36.
Challenge: Apply Functional Programming to Convert Strings to URL Slugs
When I use the below code, everything else works but it says that its changing the Global variable, the console.log shows that the Global variable is not changing. What is it that I am missing?
// the global variable
var globalTitle = "Winter Is Coming";
// Add your code below this line
function urlSlug(title1) {
let title = title1.slice();
title = (title.toLowerCase().split(/\W+/));
title[title.length-1] == 0 ? title.pop() : null;
title[0].length ==0 ? title.shift() : null;
console.log(title);
console.log(globalTitle);
return title.join("-");
}
// Add your code above this line
var winterComing = urlSlug(globalTitle); // Should be "winter-is-coming"
console.log(winterComing);
console.log(globalTitle);
I need help please.
I my console.log dose not keep the quotation marks. so I’m not passing. Just to see if it was the solution i cam up with i tried out both the first and second solutions and they don’t keep the quotations as well. I don’t know what i am doing wrong.
my solution :
return tittle
.toLowercase()
.split(/\s+/)
.join("-");
i know its very close to the second solution so it must be something I’m not seeing.
When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.
See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.
Note: Backticks are not single quotes.
However, I would really suggest you open your own thread. Click “Get Help” and then “Ask for help”. This will make a forum thread with your code and some information you can fill out.
You can post solutions that invite discussion (like asking how the solution works, or asking about certain parts of the solution). But please don’t just post your solution for the sake of sharing it.
We have set your post to unlisted. Thanks for your understanding.
It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge.
We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.