Here is my sample code for HTML And CSS
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>
My goal here is to display different shapes in 9 boxes all together at once and I'm starting out first to display a shape in all the boxes but when I use this code, nothing shows up. Also, I've checked for codes about getting elements about classes, it seems to be a bit more than getting ids. And I've tried using for loops to be able to access all the elements but I don't know why it doesnt work. :/
There were few syntax errors, missing
}
: