Push() Pop()

Array Method practice

by trentHarlem

HTML

<p>Click the button to "pop()" or remove an item from the end of one array <br> and add or "push()" that element to the end of another array.</p>

<button onclick="push()">PUSH to CART</button>

<p id="store"></p>
<p id="myCart"></p>

JavaScript

var fruits = ["Bananas", "Oranges", "Apples", "Mango"];
const cart = []
const store = document.getElementById('store')
const myCart = document.getElementById('myCart')
store.innerHTML = `'Fruits' ${fruits}`;
myCart.innerHTML = `'My Cart' ${cart}`;

function push() {
  let item = fruits.pop();
  cart.push(item);
  store.innerHTML = `'Fruits' ${fruits}`;
  myCart.innerHTML = `'My Cart' ${cart}`;
  if (fruits.length === 0) {
    store.innerHTML = `'SOLD OUT'`;

  }
}