Back to Shut the Box Project
Shut the Box Project - JS file
Additional Scripts One
Instructions:
Use the block of code below to add to your stbScripts.js file. This code will be the instructions for what happens when you click on a tile. Copy and paste this code into the very top of your JS file.
// global variables initiated var rand, rand2, total, selectCount=0; //making new arrays to hold total tile value and score of leftover tiles tileTotal = new Array(); currentTiles = new Array(1,2,3,4,5,6,7,8,9); //this function will keep track of what tiles have been selected // and only allow user to select correct total based on dice function select(obj) { // sum current tiles var tempTotal=0; var img = document.getElementById(obj); tileTotal[selectCount]=obj; for (var i=0; i<tileTotal.length; i++) { tempTotal += tileTotal[i]; }; alert(tempTotal); if (tempTotal<total) { img.style.visibility="hidden"; //change the array holding current tiles // to input a zero for the original value currentTiles.splice(obj-1,1,0); //increase selectCount which tracks how many tiles are selected selectCount ++; } else {alert(tempTotal+" is a total beyond your roll.")}; };