function bindCheckbox() {
let inputCheckbox = document.querySelectorAll('input[type=checkbox]');
let favoriteList = document.getElementById('favorites');
inputCheckbox.forEach(function(element, index) {
inputCheckbox[index].addEventListener('change', function() {
let fav = localStorage.getItem('favoList') || [];
console.log(fav);
let joke = this;
if(joke.checked && joke.parentNode.parentNode.id === 'list-of-jokes') {
addFavorite(joke.id, joke.parentNode.innerText, fav);
}
});
}
}
function addFavorite(idNum, jokeText, fav) {
let norrisJoke = [{
id: idNum,
joke: jokeText
}];
console.log(fav);
let favorites = fav;
console.log(idNum, jokeText);
console.log(norrisJoke);
favorites.push(norrisJoke);
localStorage.setItem('favoList', JSON.stringify(norrisJoke));
}
the value should be pushed into fav element, but that is kind of inside a closure. So the value should be pushed inside an innerfunction and stored inside an element inside the outer function. The localstorage outputs [object object] and no value of norrisjoke.