HTML and CSS Reference
In-Depth Information
5. We deine a funcion to quickly clear all the ingredients on hand if the player needs
to trash the sushi for selecing the wrong ingredients as given in the following code:
game.trashSushi = function() {
game.sushiOnHand.length = 0; // clear it
6. Let's move back to the view.js ile. There are some mouse interacion events for
the DOM user interface. The following internal funcion inside the view.js file sets
up the DOM elements for the clicking events:
function initDOMElements() {
var ingredients =
for (var i=0, len=ingredients.length; i<len; i++) {
var element = ingredients[i];
element.onclick = ingredientOnClick;
// trash button
var deleteButton = document.getElementById
deleteButton.onclick = function(){
// logic of clicking the ingredients
// reference of 3 layers in sushi board
// for the ingredientOnClick function to use
var others = document.getElementById('others');
var rices = document.getElementById('rices');
var seaweeds = document.getElementById('seaweeds');
var ingredientOnClick = function() {
var type = this.dataset.type;
game.sushiOnHand = game.sushiOnHand.sort();
Search WWH ::

Custom Search