sei-ec-remote / project-1-issues

Open new issues here
1 stars 2 forks source link

Dry Coding #215

Closed RyanCLuis closed 11 months ago

RyanCLuis commented 11 months ago

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)

    let mindsFound = 0
    // checking the top 3 divs
    mindsFound += checkTile(r-1, c-1) // this is top left
    mindsFound += checkTile(r-1, c) // this is top 
    mindsFound += checkTile(r-1, c+1) // this is top right
    // checking left and right
    mindsFound += checkTile(r, c-1) // this is left
    mindsFound += checkTile(r, c+1) // this is right
    // this is bottom
    mindsFound += checkTile(r+1, c-1) // this is bottom left
    mindsFound += checkTile(r+1, c) // this is bottom 
    mindsFound += checkTile(r+1, c+1) // this is bottom right

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

timmshinbone commented 11 months ago

Share the checkTile function and your html

RyanCLuis commented 11 months ago
function checkTile(r, c) {
    if (r < 0 || r >= rows || c < 0 || c >+ columns) {
        return 0
    }
    if (mindsLocation.includes(`${r}-${c}`)) {
        return 1
    }
    return 0
}
RyanCLuis commented 11 months ago
<!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>
timmshinbone commented 11 months ago

Ok so where are the r and c coming from? Can you share the code that's generating those values?

RyanCLuis commented 11 months ago
    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

RyanCLuis commented 11 months ago
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

timmshinbone commented 11 months ago

ok let's look in a breakout room