Hello,
I need help to finish the day of the race project, https://www.codecademy.com/paths/analyze-data-with-r/tracks/introduction-to-programming-in-r/modules/intro-to-programming-in-r/projects/day-of-the-race-project-R
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.
- 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.
1 Like