Making the sushi
In this task, we add the logic to composite the sushi by selecting the ingredients.
Prepare for lift off
The following figure shows the recipes of the sushi:
Engage thrusters
Follow the given steps to create the sushi:
We need a function to compare two given arrays. The array is in one dimension only so we don't need any deep comparison. Put the following comparing function in the
helpers.js
file:game.helper.arrayIsEqual = function(array1, array2) { if (array1.length !== array2.length) { return false; } for (var i = 0, len=array1.length; i < len; i++) { if (array1[i] !== array2[i]) { return false; } } return true; };
Then we need another helper function that clears all the children nodes inside a given DOM element. Defining the following function inside the
helpers.js
file helps us to keep a cleaner code base:game.helper.clearChildren = function(node) { while (node.lastChild) { node.removeChild(node.lastChild); } };
We use three layers to...