Project - Race Day - I have know idea why this code doesn't work

Hello,
Can anybody help me to understand why my code does not give the input I need (in case the age is >= 18 and its late registration). Thank you very much in advance.

var name = 'Kamil';
var lastName = 'Koenig';
var age = 19;
var regTime = 2; //1 early, 2 = late
var startTime; //1 = 9:30 ; 2 = 11:00; 3 = 12:30;

if (age < 18) {
  startTime = 3;
} else if (age => 18 && regTime === 1){
  startTime = 1; 
} else if (age => 18 && regTime === 2) {
  startTime = 2;
}

var displayTime = '';

switch (startTime) {
  case 1:
    displayTime = '9:30';
    break;
  case 2:
    displayTime = '11:00';
    break;
  case 3:
    displayTime = '12:30';
    break;
}


console.log(`Hello ${name} ${lastName}. You have registered on the race. Your run will start on ${displayTime}.`);

In case someone is >= 18 yers old and regTime is 2 (late registration) the program should set displayTime to 11:00 but always print 9:00 is age is >= 18 regardless of late registration.

=> is not the greater then or equal to operator.

1 Like

Thanks!!! I was staring at this code for half hour and couldn’t find the error.

the most obvious error was a mistake in the comparison operator, so you could use a debugger, or if you want to do it manually, you could do:

if (age < 18) {
  startTime = 3;
} else if ( regTime === 1){
  startTime = 1; 
} else if ( regTime === 2) {
  startTime = 2;
}

// rest of the code

now you know regTime works fine, so there has to be a problem with =>, so then you could attempt to use greater then (>). Now your code almost works.

just a few thinking steps to help you in future debug sessions.

teaching yourself to work and think this way is such a massive boost for programming (and not getting stuck too long :stuck_out_tongue: )

This topic was automatically closed 18 hours after the last reply. New replies are no longer allowed.