Help creating a basic function

Hi. First thing first, this appears to be a homework question, so please be aware of our homework policy. FAQ: Homework Policy. Please don't post homework questions verbatim like this.

A good place to get comfortable with R is the book, R4DS. It's free online at https://r4ds.had.co.nz/

It has a nice chapter on understanding and creating functions,
https://r4ds.had.co.nz/functions.html

I'd work through this chapter and the examples provided, and see if you're able to create your function.

If you have specific questions, bring them back here. (Ideally with a reprex)