I am trying to write a function that will iterate through an array with an if statement. I would like the function to perform a differently for each element following the first failure. I have been circling around it for a short while and thought I’d ask for some help.
Below is my current code. Thanks.
function highLight(){
let moneyLeft = document.getElementById('spending').value;
for (let i =0; i<notesCollection.length; i++){
if (Number(notesCollection[i].cost) <= moneyLeft){
notesCollection[i].highlight= true;
moneyLeft = moneyLeft - notesCollection[i].cost;
}
else{
notesCollection[i].highlight = false;
}
}
loadNotes();
titleList();
}