Hey all, I’ve created a Frankenstein and need some help with dissection.
In my button click function to add the input I’m getting a reprint of the entire array each time and I can’t seem to think of a way instead to just add the new fruit to the list without printing the entire list again and again.
<h1>My favorite fruits</h1>
<input class="fruitInput" type="text" placeholder="add fruit">
<button>Add</button>
<ol class="fruitList">
</ol>
<script>
let fruits = ["Pear","Mandarin","Banana","Pineapple"];
let list = $(".fruitList");
$("button").click(() => {
let x = $(".fruitInput").val();
fruits.push(x);
$.each(fruits, (index, value) => {
$("<li/>").text(value).appendTo(list);
});
});
</script>