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 trialaaron du
5,946 PointsThis doesn't make any sense
I am trying to make an app, but I just don't get I get the notion expected output?
this is my code :
import GameKit
class equationProvider {
let multiple1 =
[
"4358 ",
"4627 ",
"3427 ",
"9384 ",
"23 ",
"4529984 ",
"3589 "
]
let multiple2 = [
"379",
"3579",
"278",
"25",
"2598753",
"5",
"185",
"1983",
"34587",
]
func random1() -> String{
let randomNumber1 = GKRandomSource.sharedRandom().nextInt(upperBound: multiple1.count)
return multiple1[randomNumber1]
}
func random2() -> String{
let randomNumber2 = GKRandomSource.sharedRandom().nextInt(upperBound: multiple2.count)
return multiple2[randomNumber2]
}
}
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var MultiplicationEquation: UILabel!
@IBOutlet weak var userInput: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
MultiplicationEquation.text = ("\(equationProvider.random1) \rtimes \(equationProvider.random2)")
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
and this is my output for the label MultiplicationEquation:
(Function) times (Function)
I am supposed to get a random number, "times" and another random number
can someone tell me what is wrong?
1 Answer
Pasan Premaratne
Treehouse TeacherHey there!
You're not calling the function in this line of code
MultiplicationEquation.text = ("\(equationProvider.random1) \rtimes \(equationProvider.random2)")
To call a function, particularly one that doesn't have arguments, you write out the function name followed by a set of empty parentheses without spaces, like so:
equationProvider.random1()
aaron du
5,946 Pointsaaron du
5,946 Pointshi pasan, after i used your method to do it it still gave me an error like this : Instance member 'random1' cannot be used on type 'equationProvider'; did you mean to use a value of this type instead?
and this is the only line i changed : MultiplicationEquation.text = ("(equationProvider.random1()) \times (equationProvider.random2())")
can you help me again? Please?
Pasan Premaratne
Treehouse TeacherPasan Premaratne
Treehouse TeacherYou need to create an instance of equation provider before you can use it. Add the following as a stored property:
let equationProvider = EquationProvider()
The code provided earlier should work now. Let me know if you have any questions