JSFiddle - React, Tailwind, and code Playground

by jsieber

HTML

<div>
<p>
Total Number of pizzas needed: <span id="pizzaNumber"></span>
</p>
</div>

JavaScript

array = [{ name: "Joe", num: 9 }, { name: "Cami", num: 3 }, { name: "Cassidy", num: 4 }];

pizzas = gimmePizza(array, 8);

function gimmePizza(array, slicesPerPizza){
	let totalSlices = this.array.reduce((accum,item) => accum + item.num, 0);
	totalPizzas =   Math.ceil(totalSlices / slicesPerPizza);
  document.getElementById("pizzaNumber").innerHTML = totalPizzas;
  return totalPizzas;
}