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>
</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;
position:relative;
}
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;
}
.furry:after {
content: 'furry';
position:absolute;
right:0;
}
.coin {
/* background-image: url('../images/coin.png'); */
background-repeat: no-repeat;
background-size: cover;
}
.coin:after {
content: 'coin';
position:absolute;
right:0;
}
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.x = Math.floor(Math.random() * 10);
this.y = Math.floor(Math.random() * 10);
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
Game.prototype.position = function(x, y) {
return x + (y * 10);
} //method to constructor
Game.prototype.start = function() {
this.board[this.position(this.coin.x, this.coin.y)].classList.add('coin');
this.board[this.position(this.furry.x, this.furry.y)].classList.add('furry');
}
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
var Game = new Game();
Game.start();