Write a function `has_more_zs` to determine which of two strings contains more instances of the letter "z". It should take as parameters two string variables and return the argument which has more occurrences of the letter "z". If neither phrase contains the letter "z", it should return: "Neither string contains the letter z." If the phrases contain the same number of "z"s, it should return: "The strings have the same number of Zs." The function must work for both capital and lowercase "z"s. Create a variable `more_zs` by passing two strings of your choice to your `has_more_zs` function.
R language
I'm just confused about what the problems are with my codes.
```R
has_more_zs <- function(a, b) {
a <- tolower(a)
b <- tolower(b)
count_a_zs <- str_count(a, "z")
count_b_zs <- str_count(b, "z")
if (is.na(count_a_zs) && is.na(count_b_zs)) {
print("Neither string contains the letter z.")
} else if (count_a_zs == count_b_zs) {
print("The strings have the same number of Zs.")
} else if (count_a_zs > count_b_zs) {
return(a)
} else {
return(b)
}
}
a <- "zigzag"
b <- "zzz"
more_zs <- has_more_zs(a, b)
```