In this block of code, “title === film.title” returns true and it should work where it is correct, but why “title === film.title” works where the wrong value is at the bottom. “! control” not returning correctly?
function addFilm(e) {
const title = titleElement.value;
const director = directorElement.value;
const url = urlElement.value;
if (title === "" || director === "" || url === "") {
UI.displayMessages( "danger", "Alanları doldurunuz");
} else {
let control = false;
const filmlist = Storage.getFilmsFromStorage();
filmlist.forEach(function (film) {
if (title === film.title) {
control = true;
}
});
if (!control) {
const newFilm = new Film(title, director, url);
UI.addFilmToUI(newFilm);
Storage.addFilmToStorage(newFilm);
UI.displayMessages("success", "Film basarili eklendi");
UI.clearInputs(titleElement, directorElement, urlElement);
e.preventDefault();
} else {
UI.displayMessages("danger", "Eklemeye calistiginiz film sistemde mevcuttur");
}
}
e.preventDefault();
}