Writing functions with 2 variables as functions in R

This was the correct answer:
percentage_of_goals <- function(x,y) {
xy_total = x + y
(x/xy_total) * 100
}
home_percent <- percentage_of_goals(scores$home_goals, scores$away_goals)
My question is below:
Why is it not necessary to have your initial function have a (y/xy_total) * 100 as well ? If we have 2 arguments shouldn’t we take into account both the home_goals and away_goals as x and y as well ?

percentage_of_goals <- function(x,y) {
xy_total = x + y
(x/xy_total) * 100
(y/xy_total) * 100
}

1 Like

Hi @fullpopfreddy,

Can you please add the mission screen link? This is will allow us to help you better. :slightly_smiling_face:

Thanks,
Sahil