Hi, so my solution to this project seems to be faulty. I am not getting the expected output and can not seem to find the issue to why that is. Can somebody explain what i have done wrong ??
https://gist.github.com/codecademydev/70fb06d6aaf503a958b19d8a9a9b7938
Hello @arc4084987142, welcome to the forums!
The issues seems to be with this line of code:
storyWords = storyWords.filter((word) => (word.length > 10 ? "" : false));
Which seems to be returning an empty list ([]
), and so when you perform storyWords.join("")
at the end, the only non-empty string in the list is "stunning"
. I believe the reason for this is that the function you’re passing into filter should return true
for all values that you want to keep in the list (I’m assuming that’s all words with a length less than 10)? As it is now, if a word is longer than ten letters, then the function returns ""
(which JS evaluates to false
) or the function explicitly returns false
—so in either case, every word of length less than and upto or above ten (i.e. every word in the list) gets filtered out. If you want to read more about JS’ filter()
method, this article is pretty good.
I hope that helps!
Wow thank you! I had been scratching my head trying to figure out what was wrong.
Yes changing “false” to “true” helped to print out the text correctly with the correct grammar.
Thanks again for the help, got a better understanding and will read on upon JS´filter() method