Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript JavaScript Array Iteration Methods Combining Array Methods Combining filter() and map()

Using the filter and map methods on the todos array, create an array of unfinished task strings. - I'm lost..

I have tried:

unfinishedTask = todos
  .filter( todo => `${todo.done} == false`)
  .map(todo => ({todo}));

console.log(unfinishedTask);

// Returns every todo item - True & False.

I also tried:

unfinishedTask = todos
  .filter( todo => `${todo.done = false}`)
  .map(todo => ({todo}));

console.log(unfinishedTask);

// Returns every todo item - with their values changed to false.

I've tried a handful of other stuff with !== true and I'm getting nowhere.

Points go to best answer =)

Cheers!

app.js
const todos = [
    {
        todo: 'Buy apples',
        done: false
    },
    {
        todo: 'Wash car',
        done: true
    },
    {
        todo: 'Write web app',
        done: false
    },
    {
        todo: 'Read MDN page on JavaScript arrays',
        done: true
    },
    {
        todo: 'Call mom',
        done: false
    }
];
let unfinishedTasks;

// unfinishedTasks should be: ["Buy apples", "Write web app", "Call mom"]
// Write your code below
unfinishedTask = todos
  .filter(todo => `${todo.done}` == false)
  .map(todo =>`${todo.todo}`);

2 Answers

Stuart Wright
Stuart Wright
41,101 Points

There's no need to use the template literal syntax here. Also note that you missed the s of the end of your new variable. Correct solution is:

unfinishedTasks = todos
  .filter(todo => todo.done === false)
  .map(todo => todo.todo);

Thanks a ton Stuart!

I was trying to put everything together from all the videos leading up to this challenge and I thought this situation could be solved with template literals but less is more =)

Cheers!

Matthew Turner
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Matthew Turner
Full Stack JavaScript Techdegree Graduate 16,962 Points

I am not sure why the following isn't working? I tried in my console and it works just fine. Am I missing something?

unfinishedTasks = todos
  .filter(todo => !todo.done)
  .map(todo => `${todo.todo}`);

Because you don't need to use a template literal (interpolation) on your .map todo.