Challenge: Preventing Repeat Answers

Hello guys I’d like to share my solution for the challenge mentioned in the title above if you see any issues or would like to improve my solution don’t hesitate please
(Note that my solution won’t fix rotation bug)
first i modified the Question model by adding answered property to become

data class Question(@StringRes val textResId: Int, val answer: Boolean,var answered: Boolean)

after that i set the default value for answered to false

private val questionBank = listOf(
        Question(R.string.question_australia, true,false),
        Question(R.string.question_oceans, true,false),
        Question(R.string.question_mideast, false,false),
        Question(R.string.question_africa, false,false),
        Question(R.string.question_americas, true,false),
        Question(R.string.question_asia, true,false)
    )

then i created the following function called isAnswered

private fun isAnswered(index:Int){
        if (questionBank[index].answered==true){
            trueButton.isEnabled=false
            falseButton.isEnabled=false
        }else{
            trueButton.isEnabled=true
            falseButton.isEnabled=true
        }
    }

after that I modified the nextButton listener and previousButton listener as you can see

nextButton.setOnClickListener {
            currentIndex = (currentIndex + 1) % questionBank.size
            isAnswered(currentIndex)
            updateQuestion()
        }

previousButton.setOnClickListener {
            currentIndex = (currentIndex - 1) % questionBank.size
            if (currentIndex == -1) currentIndex = questionBank.lastIndex
            isAnswered(currentIndex)
            updateQuestion()
        }

and finally I modified trueButton and falseButton to become

trueButton.setOnClickListener {
            trueButton.isEnabled=false
            falseButton.isEnabled=false
            questionBank[currentIndex].answered=true
            checkAnswer(true)
        }

falseButton.setOnClickListener {
            trueButton.isEnabled=false
            falseButton.isEnabled=false
            questionBank[currentIndex].answered=true
            checkAnswer(false)
        }

I’d like to hear your thoughts about the solution above :slight_smile: