I try to make all the trees after sorting to lowercase but For some reason, I cannot make the lower case to the listTree() work! I know that to lowercase() need to be pasted in a function in order for it to work with the array. But I am not sure how to add to the listTrees() function. Do we need to use if-else statement?
const trees = ['oak', 'Pine', 'aspen', 'Bald Cypress']
const errorElement = document.querySelector('#error')
const displayResults = document.querySelector('#displayResults')
const listTrees = () => {
let treeList = ''
trees.forEach(tree => {
treeList += `${tree} <br>`
})
displayResults.innerHTML = `${treeList} <span>${trees.length} elements long </span>`
}
listTrees()
document.querySelector('#lowerTrees').onclick = () => {
if (trees.length > 0) {
trees.lowercase()
listTrees()
}
else {
errorElement.textContent = 'Dude, I cannot remove the last tree cause there are NO TREES!'
}
}