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,100 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
Matthew Turner
Full Stack JavaScript Techdegree Student 9,130 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}`);