0

This is my code thus far for a getCoordinates function that produces a list of coordinates in a grid.

getCoordinates = () => {
        let result = []
        for (int i = 1; i <= this.state.gridSize; i++){
            for (int j = 1; j <= this.state.gridSize; j++){
                result.push([i*100, j*100])
            }
        }
        return result;
};

I want to return something like for gridSize = 4

[[100, 100], [100, 200], [100, 300], [100, 400],
[200, 100], [200, 200], [200, 300], [200, 400],
[300, 100], [300, 200], [300, 300], [300, 400],
[400, 100], [400, 200], [400, 300], [400, 400]]

Can anyone please help me get the correct syntax?

1

1 Answer 1

0

The issue here is with the declaration of the variables i and j. Currently they're declared with Java (or similar) syntax. Instead those int key words should be replaced with let.

Like this:

getCoordinates = () => {
    let result = []
    for (let i = 1; i <= this.state.gridSize; i++){
        for (let j = 1; j <= this.state.gridSize; j++){
            result.push([i*100, j*100])
        }
    }
    return result;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.