javascript - Where do i place the newBoard();? -
javascript - Where do i place the <script>newBoard();</script>? -
i've problem, need set newboard(); in javascript file. set , how phone call it? , question: can write object in code?
many help!
this html file.
<html> <head> <link href="memory.css" rel="stylesheet"> <script src="memory.js"></script> </head> <body> <h1>koen's heineken memory game:</h1> <div id="memory_board"></div> <script>newboard();</script> </body> </html> this .js file.
var memory_content = ['a','a','b','b','c','c','d','d','e','e','f','f','g','g','h','h','i','i','j','j','k','k','l','l']; var memory_values = []; var memory_tile_ids = []; var cards_turned = 0; array.prototype.memory_tile_shuffle = function(){ var = this.length, j, temp; while(--i > 0){ j = math.floor(math.random() * (i+1)); temp = this[j]; this[j] = this[i]; this[i] = temp; } } function newboard(){ cards_turned = 0; var output = ''; // de array wordt geschud. memory_content.memory_tile_shuffle(); for(var = 0; < memory_content.length; i++){ output += '<div id="tile_'+i+'" onclick="memoryfliptile(this,\''+memory_content[i]+'\')"></div>'; } document.getelementbyid('memory_board').innerhtml = output; } function memoryfliptile(tile,val){ // kijkt of de kaart nog niet omgedraaid. if(tile.innerhtml == "" && memory_values.length < 2){ // de achtergrond van de kaart. tile.style.background = 'white'; tile.innerhtml = val; if(memory_values.length == 0){ memory_values.push(val); memory_tile_ids.push(tile.id); } else if(memory_values.length == 1){ memory_values.push(val); memory_tile_ids.push(tile.id); if(memory_values[0] == memory_values[1]){ cards_turned += 2; memory_values = []; memory_tile_ids = []; if(cards_turned == memory_content.length){ alert("goed gedaan! ik zet een nieuw spel voor je klaar."); document.getelementbyid('memory_board').innerhtml = ""; newboard(); } } else { function flip2back(){ var tile_1 = document.getelementbyid(memory_tile_ids[0]); var tile_2 = document.getelementbyid(memory_tile_ids[1]); tile_1.style.background = 'url(heineken.jpg) no-repeat'; tile_1.style.backgroundsize = '111px 111px'; tile_1.innerhtml = ""; tile_2.style.background = 'url(heineken.jpg) no-repeat'; tile_2.style.backgroundsize = '111px 111px'; tile_2.innerhtml = ""; memory_values = []; memory_tile_ids = []; } (flip2back, 750); } } } }
you can phone call function on load:-
<body onload="newboard()"> <h1>koen's heineken memory game:</h1> <div id="memory_board"></div> </body> javascript html
Comments
Post a Comment