Hi there, and welcome to the forums! Think about what the
find_place function is doing.
- Set place = 1
- for each element in
race_results, check if it’s the name being looked for
- if so, return the current place and end the function
- if not, increment place by 1 and check the next name
- 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.