/**
 * This exercise requires you to write a function that counts the number of occurrences of a target word
 * in a given string.
 *
 * @param string A string that contains multiple words
 * @param target A string representing the word to count occurrences of
 * @return The number of times the target word appears in the string
 *
 * Example:
 * countOccurrences("I am a social worker and I work to help people", "work") -> 2
 * countOccurrences("I am a social worker and I work to help people", "help") -> 1
 * countOccurrences("This is an example", "example") -> 0
 */
fun countOccurrences(string: String, target: String): Int {

    // Split the given string into individual words
    val words = string.split(" ")

    // Initialize a variable to keep track of the count
    var count = 0

    // Iterate over each word in the list of words
    for (word in words) {
        // Check if the current word is equal to the target word
        if (word == target) {
            // If they match, increment the count variable
            count++
        }
    }

    return count
}
/**
 * This exercise requires you to write a function that counts the number of occurrences of a target word
 * in a given string.
 *
 * @param string A string that contains multiple words
 * @param target A string representing the word to count occurrences of
 * @return The number of times the target word appears in the string
 *
 * Example:
 * countOccurrences("I am a social worker and I work to help people", "work") -> 2
 * countOccurrences("I am a social worker and I work to help people", "help") -> 1
 * countOccurrences("This is an example", "example") -> 0
 */
fun countOccurrences(string: String, target: String): Int {
/**
 * This exercise requires you to write a function that counts the number of occurrences of a target word
 * in a given string.
 *
 * @param string A string that contains multiple words
 * @param target A string representing the word to count occurrences of
 * @return The number of times the target word appears in the string
 *
 * Example:
 * countOccurrences("I am a social worker and I work to help people", "work") -> 2
 * countOccurrences("I am a social worker and I work to help people", "help") -> 1
 * countOccurrences("This is an example", "example") -> 0
 */
fun countOccurrences(string: String, target: String): Int {

    // Split the given string into individual words
    val words = string.split(" ")

    // Initialize a variable to keep track of the count
    var count = 0

    // Iterate over each word in the list of words
    for (word in words) {
        // Check if the current word is equal to the target word
        if (word == target) {
            // If they match, increment the count variable
            count++
        }
    }

    return count
}