Race Day -

Hello All,

May i know why here in the Race Day project, all the adult runner number turns out to be += 1000 hence the running time all starts at 9:30.

I already put “else if” for condition (runnerAge>18 && !registeredEarly), why that runner late has been neglected in console.log? Thanks!

Below is the link

1 Like

Hi @chloeoscar,

you declared two variables:

const registeredEarly = true;
const runnerAge = 20;

So, in this case condition (runnerAge>18 && registeredEarly) returns true. Try to change registeredEarly or runnerAge to see another log.

I am getting confused in the if else loop …can you help me …i am getting an error :–

let raceNumber = Math.floor(Math.random() * 1000);

let registeredTime = true;

let runnersAge =19;

if (runnersAge > 18 && registeredTime == true)
{
raceNumber += 1000;
}
if(runnersAge >18 && registeredTime == true)
{
console.log(${raceNumber} Your race will start at 09:30 AM);
}
else if (runnersAge >18 && registeredTime == false)
{
console.log(${raceNumber} Your Race will start at 11:00 AM);
}
else if
{
console.log(“Run at 12:00”);
}

else if {
console.log(“Report to registration desk”)
}

I am def not skillful enough to answer, hope someone can come and answer you! :smile:

and welcome to here!

@chloeoscar,
You need to start with the true argument on the left, you need to switch and declare registerEarly = true &&…
try to group your control flows better, I create different control flow for the <18 (1) and the >18 late and early(1 if, 1 else if). the = 18 I had an issue on my code as the log appears when i run the code with <18s

you forgot backtick ` bro and you don’t have a condition to your if else statement.
hope it helps.

there is also mistake in the last statement as instead iof elseif there shuld only be else,we end else if by else and also after registration desl) there should be a semicolon.

My code returned an unexpected Syntax error. Can someone please help?

Code:

let raceNumber = Math.floor(Math.random() * 1000);
let registeredEarly = true;
let age = 30;

if (age > 18 && registeredEarly === true) {
  raceNumber += 1000;
}
if (age > 18 && registeredEarly === true) {
  console.log(`Your race starts at 9:30am, and your race number is ${raceNumber}. Good luck!`);
} else if (age > 18 && registeredEarly === false) {
  console.log(`Your race starts at 11:00am, and your race number is ${raceNumber}. Now go relax!`);
} else (age < 18) {
  console.log(`Your race starts at 12:30pm, and your race number is ${raceNumber}. Have fun and best of luck!`);
}

And Error:

} else (age < 18) {
                  ^
SyntaxError: Unexpected token {
    at createScript (vm.js:53:10)
    at Object.runInThisContext (vm.js:95:10)
    at Module._compile (module.js:543:28)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Module.runMain (module.js:605:10)
    at run (bootstrap_node.js:427:7)
    at startup (bootstrap_node.js:151:9)

Why does it not like the curly bracket after else (if age < 18) ???

1 Like

duh

I figured it out. I was using an else keyword when I should’ve been using else if

My newbie roots are showing. :stuck_out_tongue_winking_eye:

1 Like

Yeah. Just noticed it and had to write but then noticed you just got it. Pretty good! Sometimes it’s just small things …

1 Like
let raceNumber = Math.floor(Math.random() * 1000);

const registeredEarly = false;

const runnerAge = 21;

if (runnerAge > 18 && registeredEarly) {
   raceNumber += 1000;

}

if (runnerAge > 18 && registeredEarly) {
  console.log(`You will race at 9:30 am and your race number is ${raceNumber}`);
} else if (runnerAge > 18 && !registeredEarly) {
  console.log(`You will race at 11:00 am and your race number is ${raceNumber}`);
} else if (runnerAge < 18) {
  console.log(`You will rune at 12:30 pm and your race number is ${raceNumber}`);
} else if (runnerAge === 18) {
  console.log ('Please see registration desk');
}


this is my code and it seemed to work.

let registeredLate = false;

let runnersAge = 19;

let raceNumber = Math.floor(Math.random()*1000);

if(registeredLate === true){

raceNumber += 1000;}

if(raceNumber > 1000 && runnersAge > 18){

console.log(you will race at 9:30 am with the number ${raceNumber});

} else if(raceNumber < 1000 && runnersAge > 18){

console.log(you will race at 11 pm with the number ${raceNumber});

} else if(raceNumber < 1000 && runnersAge < 18) {

console.log(you will race at 12.30 pm with the number ${raceNumber});

} else {

console.log(“please see registration desk”)

}