Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Closures in Swift First Class Functions Higher Order Functions

Nan Wang
Nan Wang
10,036 Points

Create a function named removeVowels that takes a string and returns a string. Name the external argument label for the

This is my code, i dont know why it is not passing :( please help :(

extension String {

func transform(_ arguement:(String) -> String) -> String {

    return arguement(self)

}


func removeVowels(from value:String) -> String {

    var output = ""
    for char in value.characters {

        if !(char == "a" || char == "A" || char == "e" || char == "E" || char == "I" || char == "i" || char == "o" || char == "O" || char == "u" || char == "U") {
            output.append(char)
        }
    }
    return output

}

}

functions.swift
// Enter your code below

extension String {

    func transform(_ arguement:(String) -> String) -> String {

        return arguement(self)

    }


        func removeVowels(from value:String) -> String {

        var output = ""
        for char in value.characters {

            if !(char == "a" || char == "A" || char == "e" || char == "E" || char == "I" || char == "i" || char == "o" || char == "O" || char == "u" || char == "U") {
                output.append(char)
            }
        }
        return output

    }

    }

2 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! Your function is fine, but is defined inside the extension instead of outside. When I move the last curly brace in your code up so that it closes off the extension, your code passes the second step of the challenge! Hope this helps! :sparkles:

Qasa Lee
Qasa Lee
18,916 Points
[Moderator redacted]

This may help, good luck!

Michael Hulet
Michael Hulet
47,913 Points

Hey Qasa! It's frowned upon in the community to post answers with code that can be copied and pasted to pass a challenge, especially without explanation. In the future, post code snippets that illustrate the way to accomplish the task that OP is trying to solve, but make sure that the code you post can't be copied and pasted into the challenge and pass without modification. Furthermore, be sure to give a thorough explanation about why that code is the proper method to solve the problem and how the code works, so that both OP and anyone else who comes across the question can learn and have an understanding about how to solve similar problems in the future. I've redacted the code in your answer accordingly, but feel free to re-post something similar with an explanation about why and how it does the trick. Thanks for helping out in the community!