Help with a Switch Statement scenario

Hello! I ran into an interesting scenario while doing the Race Day Module.
Link:
Race Day

I ran through all steps without issue, then decided to challenge myself and try it out using Switch Statements instead of If Then statements.
On step 7 it asks: “" Youth registrants run at 12:30 pm (regardless of registration)
For people who are under 18, log a statement to the console telling them that they will race at 12:30 pm. Include their raceNumber . “”

I need the syntax to say " If the racer is younger than 18, then his race number will be LESS than 1000, AND he will race at 12:30pm, regardless whether he registered early or late.
When I edit the value of “registered Early” to value to true, the code assigns a race number higher than 1000, but it is supposed to be less than 1000. When False, it is less than 1000.

I do not know what syntax to use to keep his race number less than 1000. In my head, I am thinking I need to somehow make the CASE ignore the raceNumber variable, and only focus on the age variable. It’s probably very simple, or is it a limitation of switch statements that’s only possible with if/then statements? An experienced coder would be able to solve the problem, so I’m trying to gain experience by finding a solution (failing so far).

This is my current code:

let raceNumber = Math.floor(Math.random() * 1000);
let earlyReg = false ;
let age = 17 ;

  switch (age && earlyReg) {
  case age > 18 && true: 
  raceNumber += 1000;
  console.log(`${raceNumber} will race at 9:30am`);
  break;
  case age > 18 && false:
  console.log(`${raceNumber} will race at 11:00am`);
  break;
  case age < 18:
  console.log(`${raceNumber} will race at 12:30pm`);
  break;
  default:
  console.log('see registration desk');
  break;
  }

Any advice would be great, willing to learn to fish :slight_smile: :innocent:
Please send halp!

I think a switch statement with 2 conditionals is not really normal. Because of how it’s evaluated, you would have to over-elaborate to get the results you need and even then fixing any inaccuracies would be tough as complexity grows. Moreover, it’d be hard for others to read.

Try putting a tracer statement in

  • case age < 18: like “under 18 reached!” and
  • case age > 18 && false like “false condition reached”

to give you an example of how it’s working at the moment.

switch (age && earlyReg) {
  case age > 18 && "arbitraryString": 
    console.log(`hi, you've reached the arbitrary condition`)
    console.log(`${raceNumber} will race at 9:30am`);
    break;
  case age > 18 && false:
    console.log(`${raceNumber} will race at 11:00am`);
    break;
  case age < 18:
    console.log(`${raceNumber} will race at 12:30pm`);
    raceNumber -= 1000;
    console.log('under 18!')
    break;
  default:
    console.log('see registration desk');
    break;
  }

age = 17
switch (age) {
  
  case age < 17:
    console.log(`${raceNumber} will race at 12:30pm`);    
    break;
 
  default:
    console.log("nothing happened!")

}

I see what you’re saying i think! so instead of forcing the result, kind of lead the code to the result with extra steps. I’m glad I posted this, I now see that switch statements and if/then statements aren’t exactly interchangeable. I think that bit of insight will help my thinking in the future as well.
thanks so much!

(Just to be clear the code in my examples won’t run as expected, you’ll see if you copy/paste :sweat_smile: )

Also i had a typo: The number should be 18 to highlight how case doesn’t really work in this way.

age = 17
switch (age) {
  
  case age < 18:
    console.log(`${raceNumber} will race at 12:30pm`);    
    break;
 
  default:
    console.log("nothing happened!")

}