lundi 8 février 2021

i wan to convert method to a function and if statement and return the answer to a global variable

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);
    });

this is what i'm trying to get where to result is return in a global variable filterMovies

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

Aucun commentaire:

Enregistrer un commentaire