Home > front end >  getting an error with my closing curly brackets
getting an error with my closing curly brackets

Time:04-04

i am getting an error saying it's expecting a comma in place of a curly bracket but when i do what is suggested i get another error saying it can't match the curly braces now.

if (page === "Goexploring") {
      axios
        .get(process.env.NATIONAL_PARK_API_URL)
        .then((response) => {
          console.log(response);
          let hikingActivity = [];
          response.data.data[0].parks.forEach((parks) => {
            let output = "";
            hikingActivity.forEach((parks, index) => {
              output  = `${parks.states}: ${parks.states[activities]}, `;
            return parks.states === "TN";
          })
          console.log(hikingActivity);
          state.Goexploring.parks = hikingActivity;
          done();
        })
        .catch((err) => console.log(err));
      }
    }),
  },
});

have adjusted things adding commas, braces and taking out braces and commas and still getting an error. maybe someone will see it differently. lol

CodePudding user response:

Fix it like this:

if (page === "Goexploring") {
    axios.get(process.env.NATIONAL_PARK_API_URL).then((response) => {
        console.log(response);
        let hikingActivity = [];
        response.data.data[0].parks
            .forEach((parks) => {
                let output = "";
                hikingActivity.forEach((parks, index) => {
                    output  = `${parks.states}: ${parks.states[activities]}, `;
                    return parks.states === "TN";
                });
                console.log(hikingActivity);
                state.Goexploring.parks = hikingActivity;
                done();
            })
            .catch((err) => console.log(err));
    });
}

The bracket pair colorizer (vscode extension) can help you for finding the errors like this.

CodePudding user response:

Here is the correctly formatted code:

if (page === 'Goexploring') {
  axios
    .get(process.env.NATIONAL_PARK_API_URL)
    .then((response) => {
      console.log(response);
      let hikingActivity = [];
      response.data.data[0].parks.forEach((parks) => {
        let output = '';
        hikingActivity.forEach((parks, index) => {
          output  = `${parks.states}: ${parks.states[activities]}, `;
          return parks.states === 'TN';
        });
        console.log(hikingActivity);
        state.Goexploring.parks = hikingActivity;
        done();
      });
    })
    .catch((err) => console.log(err));
}

Another thing you should have a look at is your usage of forEach. As per the docs, forEach does not return anything. You may wan't to check out map if you want to build an array for example.

  • Related