Created a function & structured logic