Wasting Pizzas
We continue in the Speedy Chef project folder throughout this section.
What we will be doing
This section will involve finishing our Speedy Chef project. One of the remaining steps is to check the chef has completed all the required steps before adding the pizza to the oven.
If the pizza is wrong, it will be wasted, and that is what we are going to cover now. Later we will add some stats to the game, so we can track the wasted pizzas in a variable.
Storing wasted pizzas
Add the following near the rest of our variables:
let wastedPizzas = 0;
Then we can update this in a function at the bottom of our script:
function wastedPizza() {
// increase variable for stats later
wastedPizzas++;
// clear steps ready for next pizza
completedSteps = [];
// clear canvas
clearCanvas();
};
In the HTML, we already have a waste button:
<button id='waste' class="delete_btn">WASTE 🗑</button>
And this will call our wastedPizza
function when clicked. Add the following at the bottom of the script:
document.querySelector('#waste').addEventListener('click', wastedPizza);
And this prepares us up for the next lesson where we will check the chef has taken the correct steps, and if not, this function will again be called.