If/else troubles- "uncaught syntax error"

I can’t find my error in this if/else code. Visual Studio Code gives me no errors but the console returns a syntax error.

let gear = true;
let car = true;
let location = 'a';
if (gear === true && car === true) {
	console.log(`Gear = ${gear}, Car = ${car}. All set, see you there`);
} else if (gear === true) {
	console.log(
		`Gear = ${gear}, Car = ${car}. Sounds like you need a ride. We'll pick you up at location ${location}`
	);
} else {
	console.log(
		`Gear = ${gear}, Car = ${car}. You're not qualified for the trip.`
	);
}

What’s the syntax error you’re getting? I don’t get any errors running your code.

1 Like

@colinthornton I just updated my post so the error should show now. It says ‘location’ was already declared. Thanks

Ah, it looks like the image wasn’t displaying in the post before. Somewhere above this code in the same scope, you have a line with let location already, so it’s getting mad at this line:

let location = 'a';

You need to either change the name of the location variable, or just reassign its value.

1 Like

Thanks. Yeah, I have looked and there is no previous declaration of location. There was code above it but I commented it out. I even erased it all just to be sure but it still returns that error. I also cleared the console. So I don’t know why it’s saying that.

But you’re right, changing it did work. I just don’t understand why ‘location’ was causing problems when it was only declared in that code. Like I said, I erased everything else.