DEV Community

herby0sbourne
herby0sbourne

Posted on

Convert Method to function and if statement

const filterMovies = !filter ? movies : movies.filter((movie) => movie.info.title.includes(filter));

    filterMovies.forEach((movie) => {
        const movieEl = document.createElement('li');
        let text = movie.info.title + ' - ';
        for (const key in movie.info) {
            if (key !== 'title') {
                text = text + `${key}: ${movie.info[key]}`;                
            }
        }
        movieEl.textContent = text;
        movieList.append(movieEl);
    });
Enter fullscreen mode Exit fullscreen mode

this is what i'm trying to get but it returns the function and not the data

 const filterMovies = function filterMoviesHandler() {
        if (!filter) {
            movies
        } else {
            movies.filter((movie) => movie.info.title.includes(filter));
        }  

    };
Enter fullscreen mode Exit fullscreen mode

Top comments (0)