Day of the Race

I need help to finish the day of the race project,

the task number 14: “…Edit the function so that the function returns 0 for an unknown name instead.”.

How do I do it?

Hi there, and welcome to the forums! Think about what the find_place function is doing.

  1. Set place = 1
  2. for each element in race_results, check if it’s the name being looked for
  3. if so, return the current place and end the function
  4. if not, increment place by 1 and check the next name
  5. if no runners in race, return place and print it

You can only return once in R, anything in a function after a return statement will never be reached. Therefore the process will only ever reach Step 5 if the name entered is not one of the runners. This means that you can just change the last return statement in the function to return(0), as it will only be run if the condition you want in step 14 is met.

1 Like