Forum General

True/False Quiz: how to show incorrect answers at the end of quiz

avillegas16avillegas16 Member ✭✭

I am working on a True/False Quiz. Here is part of my code for setting the questions in the quiz and also the "ResultsPage". The ResultsPage, however, only indicates the score (i.e. "5 out of 14"), and I'd like it to indicate which questions were the "errors". How best to go about this? Thanks.

QuizPageModel.cs
questions = new List()
{
new Question() { QuestionText="1=2", Answer=false } ,

            new Question() { QuestionText="2=5", Answer=false },
            new Question() { QuestionText="5=2+3", Answer=true},

            new Question() { 4*4=8", Answer=false },

        };

//True/False

        AnsweredTrue = new Command(async () =>
        {
        Debug.WriteLine("True button pressed");

            // check if answer is correct
            if (_currentAnswerValue == true)

                score++;
            AnsweredFalse = new Command(async () =>
        {
        Debug.WriteLine("False button pressed");



        // check if answer is correct
        if (_currentAnswerValue == false)
                score++;

        else
            {


            }

ResultsPage.xaml

ResultsPage.xaml.cs
public ResultsPage(int score, int total)
{
InitializeComponent();

    ScoreText.Text = $"{score} out of {total}";
}

Best Answers

Answers

  • avillegas16avillegas16 Member ✭✭
    edited June 30

    @LandLu Thank you for your response. I thought about adding these "error" questions into a List so I can display them later, but the thing is I am somewhat new to Xamarin Forms and C#, and this is something I haven't done so far. If you could help me out by guiding me through this, or pointing a useful reference, I'd be beyond grateful!
    Also, what do you man by " I don't know logic of how you triggered the AnsweredTrue/AnsweredFalse command"? Do you mean like what I have in my xaml (view) page? Or the rest of the code in my QuizPageModel.cs? Please let me know.

  • avillegas16avillegas16 Member ✭✭

    @LandLu I appreciate you previous response and help. However, How can I add these items (1 at a time) to a new list? I'm trying the following code, but my new list keeps being "null". Thanks once again!

    //Initialize / declare lists

    public List a;

    List<string> b= new List<string>();
    

    // List a
    a = new List()
    {
    new Question() { QuestionText="", Answer=false } ,
    new Question() { QuestionText="", Answer=false },
    new Question() { QuestionText="", Answer=true },
    new Question() { QuestionText="", Answer=false },
    new Question() { QuestionText="" , Answer=true },
    new Question() { QuestionText="", Answer=false },
    new Question() { QuestionText="", Answer=false },

        };
    

    //Add method---this is what I tried for adding items
    if (_currentAnswerValue == false)
    score++;

            else
            {
                b.Add(QuestionText.ToString());
    
  • LandLuLandLu Member, Xamarin Team Xamurai

    I saw you had opened a new thread here:
    https://forums.xamarin.com/discussion/183394/pass-list-to-another-view-and-display-it
    We could discuss it there.

  • avillegas16avillegas16 Member ✭✭

    Yes @LandLu . How do I close a thread here?

Sign In or Register to comment.