0
    let verbList: [String] = ["hacer", "ser", "estar"]
let POVList: [String] = ["él / usted","ella / usted","ellas / ustedes","ellos / ustedes","tú","yo","nosotros",]
let correctConjugation: [[String]] = [["hace","hace","hacen","hacen","haces","hago","hacemos"], ["es","es","son","son","eres","soy","somos"], ["está","está","estan","estan","estas","estoy","estamos"]]


func randomVerb() -> Int {                          //creates and returns a random number for the prefix arrray
    var randomVerb = Int(arc4random_uniform(3))
    return randomVerb
}

func randomPrefix() -> Int {                        //creates and returns a random number for the verb array
    var randomPrefix = Int(arc4random_uniform(7))
    return randomPrefix
}


@IBAction func changeVerb(sender: AnyObject) {

    Verb.text = verbList[randomVerb()]
    POV.text = POVList[randomPrefix()]

    userResponse.backgroundColor = UIColor.whiteColor()
    userResponse.text = ""


}


@IBAction func checkResponse(sender: AnyObject) {

    var userResponseA: String
    userResponseA = userResponse.text
    if (userResponseA == correctConjugation[randomVerb()[randomPrefix()]]){
        userResponse.backgroundColor = UIColor.greenColor()
    } else {
        userResponse.backgroundColor = UIColor.redColor()
    }

}

So I get two errors here (in the if statement in checkResponse): first, "int does not have a member named 'subscript'" and if I just take out the call for the function in the if statement I get: "'String' is not convertible to 'Mirror Disposition'"

I really have no idea why this is not working. Bear with me, as I am an Xcode noob just trying to get a better grade in spanish.

4
  • This isn't about the problem you're having, but the way you have that set up you're showing a random pair, then testing against a newly generated random pair in checkResponse(). Commented Nov 13, 2014 at 2:20
  • Oh darn so in other words this won't work... could I create a variable in the random # generator functions to store the random number and return that variable to check the response? Commented Nov 13, 2014 at 2:33
  • Just add two vars up by your lists, and set them from changeVerb(). I'll add to my answer below... Commented Nov 13, 2014 at 2:34
  • Having variable at the instance level lets them be accessible from all your different functions - see my update below. Commented Nov 13, 2014 at 2:38

1 Answer 1

1

Very close - just need to have your subscripts separated:

if (userResponseA == correctConjugation[randomVerb()][randomPrefix()]) {
    // ...
}

When working with an array of arrays (in this case correctConjugation), each subscript takes you one level down.


For the other issue, you want a couple variables to hold the current verb and prefix indexes:

class VC: UIViewController {
    // list declarations here
    var verbIndex = 0
    var povIndex = 0

    @IBAction func changeVerb(sender: AnyObject) {
        verbIndex = randomVerb()
        povIndex = randomPrefix()

        Verb.text = verbList[verbIndex]
        POV.text = POVList[povIndex]

        userResponse.backgroundColor = UIColor.whiteColor()
        userResponse.text = ""
    }

    @IBAction func checkResponse(sender: AnyObject) {
        var userResponseA = userResponse.text

        if (userResponseA == correctConjugation[verbIndex][povIndex]){
            userResponse.backgroundColor = UIColor.greenColor()
        } else {
            userResponse.backgroundColor = UIColor.redColor()
        }
    }
}
Sign up to request clarification or add additional context in comments.

3 Comments

That fixed that - I didn't know each subscript took you into the next dream. thanks
hmm so I think I'm following you and we are storing the random values to use them to check the user response (which makes total sense) but the program still is not recognizing when the userResponseA = correctConjugation. Could I be referencing the wrong parts of the array? So for example if "el" and "ser" is generated, the correctConjugation should reference "es"
Wait never mind I typed it in wrong :0... Thank you!

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.