I am relatively new to coding and I have been tasked with creating a game using JavaScript where a random cell is selected and the player must attempt to guess which cell it is (the one chosen randomly) within a table. Upon selecting the correct cell, the game should notify you that you have indeed made the right guess. However, I am encountering some difficulties figuring out how to implement this logic into my code. So far, what I have managed to do is create the table structure and make certain cells turn red when clicked on. Any guidance or assistance in resolving this issue would be greatly appreciated.
Below is the current code that I have developed if it helps:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
body {
text-align: center;
}
table,
th,
td {
border: 0px solid white;
border-collapse: collapse;
width: 45%;
height: 55px;
text-align: center;
vertical-align: center;
table-layout: fixed;
}
table.center {
margin-left: auto;
...
function tableText(col){
if (typeof event!=='undefined')
el=event.srcElement
for (var i = 0; i < el.parentNode.cells.length; i++)
el.parentNode.cells[i].style.backgroundColor=''
el.style.backgroundColor=col
}
</script>
</html>
</script>
</html>