'getting an error with my closing curly brackets
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
Solution 1:[1]
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.
Solution 2:[2]
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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Hamid Haghdoost |
| Solution 2 | alexanderdavide |
