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
Hamza Ansari
1,014 PointsWhat's wrong with this function?
For some reason I'm getting 4 errors in this code: Unknown type name 'func', expected function body after function declarator (which I thought I included), type specifier missing defaults to 'int', and expected ')'. Here's the code for the function I'm trying to write, which is supposed to add a vote to a poll choice when the button for that choice is pressed:
func addVote(countOption1: String) -> String {
let result = countOption1 +=1 return result } What am I missing from this code to execute that function, and how can I add the name of the choice that the vote is stored for? Again all votes need to be stored on my Parse.com account and I'm trying to return the result for each poll. The button I'm trying to add above is just for one option, but will be in a poll with 2-4 additional options.
2 Answers
obey me
1,135 PointsI ran you code there was not problem i did a sample test it return it , just make sure that you leave some space between the code
func addVote(countOption1 :String) ->String {
let result = countOption1 + countOption1
return result
}
Tunde Adegoroye
20,597 PointsWouldn't it be better for the return value to be an Int rather than a String since votes will be numbers this may be an issue with it