JSFiddle - React, Tailwind, and code Playground
HTML
<body>
<section id='score'>
<div>
SCORE<br>
<strong>0</strong>
</div>
</section>
<section id='board'>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</section>
<section id='over' class='invisible'>
</section>
<script src='js/out.js'></script>
</body>
CSS
* {
box-sizing: border-box;
}
body {
margin: 0;
padding: 0;
}
section#score {
width: 100%;
}
#board {
width: 640px;
height: 640px;
margin: 1em auto;
}
#board > div {
border: 1px solid black;
float: left;
width: 64px;
height: 64px;
}
section#score div {
width: 10em;
height: 3em;
text-align: center;
padding: 0.5em;
background-color: rgba(211,211,211, 0.75);
border: 1px solid lightgray;
border-radius: 1px;
box-shadow: 1px 1px 5px 1px lightgray;
margin: 1em auto;
}
.furry {
background-image: url('../images/furry.png');
background-repeat: no-repeat;
background-size: cover;
}
.coin {
background-image: url('../images/coin.png');
background-repeat: no-repeat;
background-size: cover;
}
section#over {
position: fixed;
width: 100%;
height: 100%;
left: 0;
top: 0;
z-index: 1;
padding: 10px;
background-color: rgba(255, 255, 0, 0.75);
}
section#over pre {
display: inline-block;
width: 100%;
text-align: center;
font-size: 10px;
font-weight: bolder;
color: brown;
}
.invisible {
display: none;
}
JavaScript
function Furry() {
this.board=document.querySelectorAll('#board div');
this.x = 0;
this.y = 0;
this.direction = "right";
} //constructor of furry
function Game() {
this.board=document.querySelectorAll('#board div');
this.furry = new Furry;
this.coin = new Coin;
this.score = 0;
} //constructor of game
function Coin() {
this.x = Math.floor(Math.random() * 10);
this.y = Math.floor(Math.random() * 10);
}//constructor of coins which will be collected by fury
Game.prototype.position = function() {
return x + (y * 10);
} //method to constructor
showFurry=function(){
this.x = Math.floor(Math.random() * 10);
this.y = Math.floor(Math.random() * 10);
this.board[ this.position(this.furry.x , this.furry.y) ].classList.add('furry');
} //rendering furry
showCoin= function(){
this.board[ this.position(this.coin.x,this.coin.y) ].classList.add('coin');
} //rendering coin