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
Please send halp!