1

I can't seem to figure out whats the issue here,

I have a swift code and I need it to gather multiple parameters. Please help:

func myBioData(myNameIs, myAgeIs) {
   println("Hello, my name is (myNameIs) and I am (myAgeIs) years old");
}
1
  • So... your problem is that the function arguments aren't being printed but instead you see "...(myNameIs)..." in the output? Commented Nov 30, 2014 at 14:49

1 Answer 1

2

There are multiple things you are doing wrong within your code here. To start off here is the right code and I will dissect it for you

func myBioData(myNameIs : String, var myAgeIs : Int) {
    println("Hello, my name is \(myNameIs) and I am \(myAgeIs) years old")
}
myBioData("Nick", 26)

First of all when you declare a parameter in Swift you need to explicitly state the type of the variable so you need to do something like this

(myNameIs: String)

Second thing to notice is that in Swift if you do not explicitly say that it's a variable that you are passing in Swift assumes that you are passing in a constant. Depending on what you are trying to do it may make a difference so I just added one as a constant and other as a variable to simply show you

Lastly when you are trying to add variables between a println you need to add a "\" before placing the variable/constant name so the syntax would be (myNameIs) would be right. Also, you should not put a semicolon at the end of the statement

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.