What's wrong with my var having a greater than sign?

let freeParkRide > 7;

switch (freeParkRide){
case ===2:
console.log(‘We can only ride 2 rides.’);
break;
}

https://www.codecademy.com/courses/introduction-to-javascript/lessons/control-flow/exercises/review-control-flow
Thks.

Hey micro5795965298! :slight_smile: How are you doing?

There’s an issue with your first line of the code.

let freeParkRide > 7;

What is the value of your variable here? Unfortunately this is a syntax error.

If you share what’s the logic you want to give to your code we may find a better solution. :slight_smile:

I was trying to make there be >7 freeParkRides total.

Alright, so you don’t know how many though, in this case if you don’t know, its value is undefined, initiate it like this:

let freeParkRide;

Then you should create something that modifies your variable. Maybe it’s a random event, maybe it’s an elaboration, in any case you should assign freeParkRide a specific value with the = operator.

What does freeParkRide mean in your code? Who decides how many free park rides there should be?

1 Like

Ok thanks.
I switched it to let freeParkRide = 8; and had a switch case=8 further on. Is it true that the syntax using the switch shortcut doesn’t allow for there to be a, for example, ‘case > 7:’ ?

So I’ll make you an example on how to use switch with booleans and cases with conditions :wink: Hopefully it doesn’t confuse you!

//initiate a variable let lifePoints; //it's value here is undefined //let's assign it a random value from 0 to 9 using the Math library of Javascript lifePoints = Math.floor(Math.random()*10); //now freeRides' value is going to be one number randomly picked between 0 and 9 //now let's use switch with a boolean value, just to learn how it works switch (true) { //here switch checks whenever the case results to be true case (lifePoints<5): //is lifePoints less than 5? If so log this phrase console.log("Your life points are low!") break; case (lifePoints>5): //is lifePoints greater than 5? If so log this phrase console.log("Your life points are high!") break; default: //if lifePoints is not less than 5 nor greater than 5, log its exact value, which we expect to be 5! console.log(`You got exactly ${lifePoints} life points`) break; }

Just select on the Javascript language and click Run as many times as you want, it will print something different any now and then.

wow, cool. Thanks! I get it now. > or < values have to be placed inside parentheses.

First Run, I got “Your life points are high!” :grinning_face_with_smiling_eyes:

2 Likes

Nah you can also do it without parentheses, I did it for clarity, but you got to have two thing to compare after the case keyword, in your example:

for example, ‘case > 7:’ ?

after the keyword case there’s no parameter, that would give you an error!

Oh yeah, that too. :sweat_smile:

1 Like

I somehow missed this! xD Haha so you’re in good health I see :muscle:

:slightly_smiling_face: :slightly_smiling_face: :slightly_smiling_face: :slightly_smiling_face: :slightly_smiling_face: :slightly_smiling_face: :slightly_smiling_face: :slightly_smiling_face: :slightly_smiling_face: :slightly_smiling_face: :slightly_smiling_face: :slightly_smiling_face: :slightly_smiling_face: :slightly_smiling_face: :slightly_smiling_face::slightly_smiling_face: :slightly_smiling_face::slightly_smiling_face: :slightly_smiling_face: :slightly_smiling_face: