- Make it possible to switch people to the other list.
**/
function sort() {
const niceListArr = sorteesArr.filter(sortee => sortee.hasBeenGood)
const naughtyListArr = sorteesArr.filter(sortee => !sortee.hasBeenGood)
niceListArr.forEach((nice) => {
console.log(`${nice.name} has been nice`)
niceList.innerHTML += `<li>${nice.name}</li>`
})
naughtyListArr.forEach((naughty) => {
console.log(`${naughty.name} has been naughty`)
naughtyList.innerHTML += `<li>${naughty.name}</li>`
})
}
const niceList = document.getElementById("nice-list")
const naughtyList = document.getElementById("naughty-list")
const btn = document.getElementById("btn")
const li = document.createElement("li")
btn.addEventListener("click", sort)
const sorteesArr = [
{
name: "David",
hasBeenGood: false
},
{
name: "Del",
hasBeenGood: true
},
{
name: "Valerie",
hasBeenGood: false
},
{
name: "Astrid",
hasBeenGood: true
}
]
/** Challenge:
- Write the JavaScript to sort the people in sorteesArr into the naughty and nice lists,
according to whether they have been good or not. Then display the names in the relevant place in
the DOM.
**/
/** Stretch goals:
- Add the option to add new names to the sorteesArr.