Closed RyanCLuis closed 11 months ago
Share the checkTile function and your html
function checkTile(r, c) {
if (r < 0 || r >= rows || c < 0 || c >+ columns) {
return 0
}
if (mindsLocation.includes(`${r}-${c}`)) {
return 1
}
return 0
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="css/style.css">
<script defer src="js/main.js"></script>
<title>Don't Blow Your Mind!</title>
</head>
<body>
<h1>Mind's Left: <span id="mind-count">0</span></h1>
<div id="tiles">
</div>
<div>
<button id="head">🥴</button>
</div>
<div>
<button>GameOver... Try Again?</button>
</div>
</body>
</html>
Ok so where are the r
and c
coming from? Can you share the code that's generating those values?
let divCoord = tile.id.split("-") // spliting "0-0" to (0, 0)
let r = parseInt(divCoord[0])
let c = parseInt(divCoord[1])
checkMinds(r, c)
}
the r and c comes from the slit of the tile.id
for (let r = 0;r < rows; r++) {
let row = []
for (let c = 0; c < columns; c++) {
// making a div tag in HTML
let tile = document.createElement("div")
tile.id = `${r}-${c}`
and the tile.id comes from the divs i made with this for loop
ok let's look in a breakout room
What's the problem you're trying to solve?
i am just wondering if i can clean up this code so its not multiple of lines. i want to know if i can combine all the tops to one statement, and all the bottoms to one statement
Post any code you think might be relevant (one fenced block per file)
If you see an error message, post it here. If you don't, what unexpected behavior are you seeing?
What is your best guess as to the source of the problem?
What things have you already tried to solve the problem?
Paste a link to your repository here
https://github.com/RyanCLuis/Minesweeper