please how can i create a click on each tiles to make a game sequences?

tag Source

The page consists of a board of tiles (default 4x4). - every 2 tiles have the same color (it could be an image, user should select 2 tiles with the same color to make them disappear. If he selects 2 tiles with different colors then they are flipped to "closed" state, and user proceeds with the next round.


var a=document.getElementById(main).onclick="f()"; 
var b= document.getElementById("1").onclick="f()"; 
var b= document.getElementById("2").onclick="f()"; 
var d= document.getElementById("3").onclick="f()"; 
var i=0; if(i=="tile1" || i=="tile2"){ i=0 } else{ i++ } } }


<div id="main"> 
<div id="1"></div> 
<div id="2"></div> 
<div id="3"></div> 
<div id="e4"></div> 


answered 6 months ago Jonny #1

I added an function to be triggered by onclick. This just changes color so you will have to adjust this to meet your needs. Hope it helps.

function f(){document.getElementById('tile1').style.backgroundColor = "red";}
function f2(){document.getElementById('tile2').style.backgroundColor = "red";}
function f3(){document.getElementById('tile3').style.backgroundColor = "red";}
function f4(){document.getElementById('tile4').style.backgroundColor = "red";}
#tile1, #tile2, #tile3, #tile4{
border:1px #000000 solid;
<div id="main"> 
<div onclick="f();" id="tile1"></div> 
<div onclick="f2();" id="tile2"></div> 
<div onclick="f3();" id="tile3"></div> 
<div onclick="f4();" id="tile4"></div> 

in essence as you click on the div it runs a function that changes the color.

comments powered by Disqus