1

These seemed to happen randomly. I did make some changes just before it stopped working but the changes were to unrelated components. This file has worked fine for weeks now; but all of a sudden the top and bottom parantheses stop highlighting each other and the value returned from this huge method causes the error elsewhere. I swear I clicked through all of these inner parentheses and they all matched up. My partner is trying to use an online tool. Additional notes: we are using the Salesforce org developer console. Also due to the youth of the project we both just log into my developer org and carefully work together on what we change lol I know that's bad practice, could that have caused this error ?

if(piece == "queen"){

            var i = pos1 - 1;
            var j = pos2 - 1;

            while(i > 0 && j > 0){

                // moving up and to the left
                let b1 = i.toString() + j.toString();
                if(board[b1] == "Space"){
                    possMoves.push(b1);
                } else if(board[b1].startsWith("Black")){
                    possMoves.push(b1);
                    break;
                } else if(board[b1].startsWith("White")){
                    break;
                }

                i--;
                j--;
            }

            var ii = pos1 - (-1);
            var jj = pos2 - 1;

            while(ii < 9 && jj > 0){
                let b2 = ii.toString() + jj.toString();
                // moving down and to the right
                if(board[b2] == "Space"){
                    possMoves.push(ii.toString() + jj.toString());
                } else if(board[b2].startsWith("Black")){
                    possMoves.push(b2);
                    break;
                } else if(board[b2].startsWith("White")){
                    break;
                }

                ii++;
                jj--;
            }

            var iii = pos1 - 1;
            var jjj = pos2 - (-1);

            while(iii > 0 && jjj < 9){
                let b3 = iii.toString() + jjj.toString();
                if(board[b3] == "Space"){
                    possMoves.push(b3);
                } else if(board[b3].startsWith("Black")){
                    possMoves.push(b3);
                    break;
                } else if(board[b3].startsWith("White")){
                    break;
                }
                // moving up and to the right

                iii--;
                jjj++;

            }

            var iiii = pos1 - (-1);
            var jjjj = pos2 - (-1);

            while(iiii < 9 && jjjj < 9){
                let b4 = iiii.toString() + jjjj.toString();
                if(board[b4] == "Space"){
                    possMoves.push(b4);
                } else if(board[b4].startsWith("Black")){
                    possMoves.push(b4);
                    break;
                } else if(board[b4].startsWith("White")){
                    break;
                }

                iiii++;
                jjjj++
            }

            // vertical move to top
            var i1 = pos1 - 1;

            while(i1 > 0){
                let r1 = i1.toString()+pos2.toString();
                if(board[r1] == "Space"){
                    possMoves.push(r1);
                } else if(board[r1].startsWith("Black")){
                    possMoves.push(r1);
                    break;
                } else if(board[r1].startsWith("White")){
                    break;
                }

                i1--;
            }

            // vertical move to bottom
            var i2 = pos1 - (-1);
            while(i2 < 9){
                let r2 = i2.toString()+pos2.toString()
                if(board[r2] == "Space"){
                    possMoves.push(r2);
                } else if(board[r2].startsWith("Black")){
                    possMoves.push(r2);
                    break;
                } else if(board[r2].startsWith("White")){
                    break;
                }

                i2++;
            }

            // horizontal move to left
            var i3 = pos2 - 1;

            while(i3 > 0){
                let r3 = pos1.toString()+i3.toString();
                if(board[r3] == "Space"){
                    possMoves.push(r3);
                } else if(board[r3].startsWith("Black")){
                    possMoves.push(r3);
                    break;
                } else if(board[r3].startsWith("White")){
                    break;
                }

                i3--;
            }

            // horizontal move to right
            var i4 = pos2 - (-1);
            while(i4 < 9){
                let r4 = pos1.toString()+i4.toString();
                if(board[r4] == "Space"){
                    possMoves.push(r4);
                } else if(board[r4].startsWith("Black")){
                    possMoves.push(r4);
                    break;
                } else if(board[r4].startsWith("White")){
                    break;
                }

                i4++;
            }

        }

enter image description here

enter image description here

3

Braces don't just stop 'finding each other'. You have a syntax error somewhere in your code that's causing the parser to stop working. I pasted your code into Visual Studio Code and found that the braces did balance. Your error likely doesn't have anything to do with braces as such; you need to share specific details of that error if you'd like assistance.

It's highly possible that editing the same file collaboratively can cause issues where changes don't match up and result in syntax errors. You should either (a) serialize access to this file; (b) use an IDE and a version control system; (c) use a JavaScript linter; or (d) all of the above.

  • Your right that wasn't the problem, HOWEVER it is very confusing that the dev console doesn't match those up like it should. Why would it not highlight them properly ? – SallyRothroat Feb 7 '18 at 16:35
  • 1
    @madmax The Developer Console can be confused into showing a curly brace as unmatched (usually the very last brace of the file), so it's not always an indicator. I don't have a specific example on hand, but I tend to run in to this every few months or so. Whenever you get this, you might take a moment to pull your code in to Eclipse or some other IDE, as they have more reliable matching. Note that you'll never get a false negative (a brace shows as matching when its unmatched), but you may get false positives (a brace shows as unmatched when it is). – sfdcfox Feb 7 '18 at 16:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.