Check out this HTML and CSS code sample!
body{
font-family: Verdana, Geneva, sans-serif;
}
.box{
width: 140px;
height: 140px;
background-color: red;
display: none;
position:relative;
margin-left: auto;
margin-right: auto;
}
.bold{
font-weight: bold;
}
.table{
border: 2px solid black;
height: 150px;
width: 150px;
}
</style>
<p class="bold">Your Time: <span id="time">0.000</span>s</p>
<table id="table">
<tbody>
<tr>
<td class="table"><div class="box"></div></td>
<td class="table"><div class="box"></div></td>
<td class="table"><div class="box"></div></td>
</tr>
<tr>
<td class="table"><div class="box"></div></td>
<td class="table"><div class="box"></div></td>
<td class="table"><div class="box"></div></td>
</tr>
<tr>
<td class="table"><div class="box"></div></td>
<td class="table"><div class="box"></div></td>
<td class="table"><div class="box"></div></td>
</tr>
</tbody>
</table>
<script type="text/javascript">
function getRandomColor() {
var letters = '0123456789ABCDEF'.split('');
var color = '#';
for (var i = 0; i < 6; i++ ) {
color += letters[Math.floor(Math.random() * 16)];
}
return color;
}
var clickedTime; var createdTime; var reactionTime;
function makeBox(){
createdTime=Date.now();
var time = Math.random();
time = 5000*time;
var box = document.getElementsByClassName("box");
setTimeout(function(){
if(Math.random()>0.5){
for (var i=0;i<box.length; i++) {
box[i].style.borderRadius="100px";
}else{
for (var i=0;i<box.length; i++) {
box[i].style.borderRadius="0";
}
for (var i=0;i<box.length; i++) {
box[i].style.backgroundColor=getRandomColor();
}
for (var i=0;i<box.length; i++) {
box[i].style.display="block";
}
createdTime=Date.now();
}, time);
}
for (var i=0;i<box.length; i++) {
box[i].onclick=function(){
clickedTime=Date.now();
reactionTime=(clickedTime-createdTime)/1000;
document.getElementById('time')[0].innerHTML=reactionTime;
this.style.display="none";
makeBox();
}
makeBox();
</script>
I am working on a project to show various shapes in 9 boxes simultaneously but only one shape at a time appears when I run this code. I have tried accessing elements by class and using loops, but it doesn't seem to work as intended. Any suggestions or alternatives would be greatly appreciated!