sei-ec-remote / project-1-issues

Open new issues here
1 stars 2 forks source link

I cant figure out why my code isn't working #196

Closed JohnArochaDev closed 11 months ago

JohnArochaDev commented 11 months ago

What's the problem you're trying to solve?

The code Im using on line 228 isn't outputting what it should, even though it works on line 154

Post any code you think might be relevant (one fenced block per file)

function cTurn() {
    cptrId()
    const boxId = comId
    const col = boxId[1]
    console.log(col)
    const row = boxId[3]
    console.log(row)
    console.log(comId)
    console.log(chart[col][row])
    if (turn === !2) {
        return
    } else if (turn === 2) {
        if (chart[col][row] === 4 || chart[col][row] === 5)
        return
    }
}

If you see an error message, post it here. If you don't, what unexpected behavior are you seeing?

script.js:228 Uncaught TypeError: Cannot read properties of undefined (reading '4')
    at cTurn (script.js:228:22)
    at script.js:237:1

What is your best guess as to the source of the problem?

Honetly I dont get it...

What things have you already tried to solve the problem?

Ive tried a lot and Im not sure whats wrong with it

Paste a link to your repository here

https://github.com/jpjpjppj/Battleship

BeccaK8 commented 11 months ago

I'm not sure which is line 228, but for this line: if (turn === !2) { try moving the not (!) to the equals to make it in inequality: if (turn !== 2) {

or simply move that code to an "else" below the if:

if (turn === 2) {
    if (chart[col][row] === 4 || char[col][row] === 5) return;
} else {
    return;
}
JohnArochaDev commented 11 months ago

Its still not working for some reason, I have it set so that once changeTurn is activated, if its turn 2 it should activate that turn and then make a choice but its not making a choice

JohnArochaDev commented 11 months ago

The function is running, and console.log's are running from it, its just not changing the values like it should

timmshinbone commented 11 months ago

ok share the console log code and the results here

JohnArochaDev commented 11 months ago

Screenshot 2023-11-30 144604

JohnArochaDev commented 11 months ago

Screenshot 2023-11-30 144713

JohnArochaDev commented 11 months ago

And here is the code running those logs

Im stuck because I have no errors, and the logs work, and the game works without this but I need the computer to make a turn obviously. If I can get it to work I can then add more steps for a better AI and get to polishing!

(I shared the picture so you could see the js:59 and see where the code was)

timmshinbone commented 11 months ago

Resolved by deciding to rework the code to display two boards at a time.