Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript JavaScript Array Iteration Methods Combining Array Methods Method Chaining

nico dev
nico dev
20,364 Points

Line 8: Unexpected token ILLEGAL - (in the filter & map challenge)

Hello everyone,

I would like to receive your insight and advice on this one, because I am a little clueless.

I honestly wrote to Support thinking it was a bug, but maybe that was a little rushed and, although I debugged this myself already a few times, I should still analyze it more, or even better, ask for some experienced eyes like yours.

I have this challenge that should be linked at the top right of this page, and the way I am trying to do it is using a template literal in the map method. However, I receive the message that I commented in the title of this question.

I honestly suspect that is more of a bug or a problem with the template literals compatibility or smth alike, but maybe there's something I am missing.

Would you please kindly take a look, and let me know your opinion, and even more importantly, if you find what I may be doing wrong, and I will be so happy and relieved to finally sort it out with your help! :)

Thank you in advance for any hint, clue, spot on, opinion, advice or any attempt to help in general!

app.js
const years = [1989, 2015, 2000, 1999, 2013, 1973, 2012];
let displayYears;

// displayYears should be: ["2015 A.D.", "2013 A.D.", "2012 A.D."]
// Write your code below
displayYears = years
  .filter(year => year>2000 && year <= 3000)
  .map(year => year = `${year} A.D.`);

console.log(displayYears);
nico dev
nico dev
20,364 Points

I forgot to comment this: I already tried it in

  • Chrome Dev Tools console, and
  • Visual Studio Code + Integrated Terminal

In both cases it worked, outputting:

["2015 A.D.", "2013 A.D.", "2012 A.D."]

2 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! Another moderator and I submitted a bug report on this yesterday. It has been reported to support. For whatever reason, this challenge will simply not accept a JavaScript template literal. However, if you use old-fashioned concatenation, it will pass! :sparkles:

nico dev
nico dev
20,364 Points

Yes, thank you Jennifer!

Samuel Ferree
Samuel Ferree
31,722 Points

weird... the challenge engine may not be running ES6 and thus can't understand the template literals. (Except it WAYYYY should) Try legacy string concatenation

const years = [1989, 2015, 2000, 1999, 2013, 1973, 2012];
let displayYears;

// displayYears should be: ["2015 A.D.", "2013 A.D.", "2012 A.D."]
// Write your code below
displayYears = years
  .filter(year => year>2000 && year <= 3000)
  .map(year => year = "" + year + " A.D.");

console.log(displayYears);
Samuel Ferree
Samuel Ferree
31,722 Points

as a small side note, you don't need to assign anything in the lambda that you pass into map

const nums = [ 1, 2, 3, 4 ];
nums.map(num => num * 2) // returns [ 2, 4, 6, 8 ]
nico dev
nico dev
20,364 Points

Thanks, Samuel Ferree,

That's something like what I am expecting to be the problem, yes.

Well, believe me or not, still a lot of testing stuff like I guess the name is Lint, need special prefixes and magical words to make it work with ES6.

I could have done the concatenation thing, you're right, but honestly I was following the instructor's style which is fully up-to-date, and he himself was using template literals. Which, in turn, was not giving me trouble, as long as I was working on my own in VSC + IT. However, when I needed to do the challenge online, I don't depend anymore in my tools, but on the challenge's.

Thank you again! At least I'm not that crazy to suspect smth like that. :)

nico dev
nico dev
20,364 Points

Wow, your 2nd comment was even more learning to me! Thank you!

I just tried it and it worked (I mean, it worked in my own environment :) ) without assigning it to year. It's getting so amazingly compact and neat! Cool!!