Skip to main content
Community site session details

Community site session details

Session Id : dX2yhAb7hqyWLke8bFUbsd
Power Apps - Building Power Apps
Unanswered

how to create quiz app

Like (0) ShareShare
ReportReport
Posted on 28 Feb 2023 12:28:19 by

i have sharepoint with question and option 1,2,3,4 columns and Answer column as well.

i want to display random question in Label control and 4 options in buttons. 

when user select correct answer it will verfiy with Answer colum,n and display message as Correct Answer through label.

how to do this any idea?

Categories:
  • LaurensM Profile Picture
    12,510 Moderator on 07 Mar 2023 at 18:08:22
    Re: how to create quiz app

    Hi @venky232,

     

    Step 3 issue:

    Since the collection is only fetched during the OnStart, make sure the OnStart has ran. I expect that your collection was empty at the time of the error.

    LaurensM_0-1678211003219.png

     

    Button DisplayMode:

    Ok to allow this, we might need to change our varEnableButtons variable and DisplayMode of the buttons slightly. Instead of storing true/false, we will store the question linked to the button that is pressed. This way we can uniquely identify which button was actually pressed and disable the other buttons.

     

    (1) Remove the varEnableButtons code from the OnStart

    (2) The question buttons OnSelect will look similar to (please adjust if necessary)

    //If you show the question text in the button text use Self.Text
    //Otherwise use QuestionLabelName.Text of the label which the button corresponds to
    Set(varEnableButtons, Self.Text)

    (3) Change the varEnableButtons code of the Next Question button:

    Set(varEnableButtons, Blank())

     (4) DisplayMode of the buttons

    If(
     //Similar remark here, change to question label text if needed
     IsBlank(varEnableButtons) || varEnableButtons = Self.Text,
     DisplayMode.Edit,
     DisplayMode.Disabled
    )

     

    Button Fill property (change button colors):

    (1) Fill property of question buttons

    If(
     IsBlank(varEnableButtons),
     Color.Orange,
     //Similar remark as before, change to question label text if needed
     varEnableButtons = Self.Text,
     Color.Green,
     Color.Red
    )

    (2) Optional HoverFill code change (of the question buttons) to improve the app UI:

     

    ColorFade(Self.Fill, -20%)

     

    Reset Timer Control:

    You will need to use the Reset(TimerControlName) function when selecting the 'Next Question' button. Additionally, you will have to restart the timer control via variables. How to start, stop & reset a Timer Control via a button is well explained in this blog post.

     

    If this solves your question, would you be so kind as to accept it as a solution.

    Thanks!

  • venky232 Profile Picture
    on 07 Mar 2023 at 04:58:34
    Re: how to create quiz app
    • when i run step 3 

    it shows error as 

    2nd argument to the randbetween function must be greater than or equal to first argument.

     

    1. Also, when user click any answer button all buttons are disabled. here i want only selected button should turn to orange and remaining button should disabled. and also once is answer is correct the button should change from orange to green, if selected button answer is false it should change colour from orange to red.
    2. i added Timer for 30sec ,once user not able to answer before the timer ,it will naviage to home screen and it will notify as time up, or user answer correct and when he click next question and the trimer will start again.

    on Timer End : i added below code but it is continuing for next question also but not restarting again when click on next question

    Set(Audio, Audio3);Notify("Time Up,better Luck Next Time",NotificationType.Information);Navigate(Screen2)

     

     

  • LaurensM Profile Picture
    12,510 Moderator on 05 Mar 2023 at 16:30:58
    Re: how to create quiz app

    Hi @venky232,

     

    First of all, my apologies for the delay between my answers!

     

    The code you showed is correct. However, keep in mind that you have to change LISTNAME to your actual list name and the upper boundary of RandBetween(1, 100) to your list length - you stated 20 questions so this would be 20. However, we will change this function slightly in our code below and changing it to 20 is no longer needed.

     

    Now looking back on my initial code, we have 1 issue: we might get duplicate questions, which is not something we want. To resolve this issue, we will need to (1) fetch all SP rows to a collection during the onstart, (2) fetch a random question from the collection and (3) make sure we remove the question from the collection when selecting a new one.

     

    (1) OnStart - locally store the questions & save a random one

    //Change LISTNAME
    ClearCollect(colQuestions, LISTNAME);
    //Save random question to a var
    Set(
     varRandomQ,
     Index(
     colQuestions,
     //Random number between 1 and the amount of rows in colQuestions
     RandBetween(1, CountRows(colQuestions))
     )
    )

     

    (2) My previous code for showing the question & validating is still the same (see previous comment)

     

    (3) Selecting a new question & removing duplicate:

    //Remove the question from our collection in order to avoid duplicates
    Remove(colQuestions, varRandomQ);
    //Save a new random question to a var
    Set(
     varRandomQ,
     Index(
     colQuestions,
     //Random number between 1 and the amount of rows in colQuestions
     RandBetween(1, CountRows(colQuestions))
     )
    )

     

    (4) Disabling buttons:

    For this requirement you would need to create a variable that starts of as 'true' and changes to 'false' once one of the buttons is pressed. The variable is reset to 'true' once a new question is selected.

     

    OnStart of the app:

    Set(varEnableButtons, true)

     Add the following to the OnSelect of the buttons:

    Set(varEnableButtons, false)

     OnSelect of the 'Next Question' button:

    Set(varEnableButtons, true)

     

    The DisplayMode of all question buttons would be:

    If(
     varEnableButtons,
     DisplayMode.Edit,
     DisplayMode.Disabled
    )

     

    (5) Save the score:

    To save the score of a person, create a variable in the OnStart and every time the correct button is pressed (see my previous code with the Notify) you add 1 to that variable:

     

    OnStart

    Set(varScore, 0)

    Correct Answer

    Set(varScore, varScore + 1)

     

    (6) Save the answer time

    This requirement will need a Timer control that starts once the first question is displayed and saves (to a collection) & resets when a new question is selected. I will link a video that will go into more detail.

     

    (7) Stop after 10 questions

    This solution will be very similar to the varScore. Start with a variable set to 0 and add 1 every time the 'Next Question' button is pressed (let's call it varAnswers).

     

    The DiplayMode of the Next Question button would be:

    If(
     varAnswers <> 10,
     DisplayMode.Edit,
     DisplayMode.Disabled
    )

    You could also show a label depicting the end of the quiz when varAnswer equals 10.

     

    If this solves your question, would you be so kind as to accept it as a solution.

    Thanks!

  • venky232 Profile Picture
    on 03 Mar 2023 at 08:47:24
    Re: how to create quiz app

    @LaurensM  can u help on above request

  • venky232 Profile Picture
    on 02 Mar 2023 at 06:21:16
    Re: how to create quiz app

    its working  but need some improvement.

    the following code i added in both Onstart properties of the screen and also Next question button  is it right?
    Set(
    varRandomQ,
    //Change listname
    Index(
    LISTNAME,
    //Random number between 1 and 100 -> change 100 to your last row number
    RandBetween(1,100)
    )
    )

     

    i want only 1 time user can select option & other buttons should disable..

    is there any change to capture score and time for answers?

    user can take 10 questions as quiz from the SharePoint list with contain 20 questions in random order.

  • LaurensM Profile Picture
    12,510 Moderator on 01 Mar 2023 at 19:25:19
    Re: how to create quiz app

    Hi @venky232,

     

    To fetch a random question, we could use the Index() & RandBetween() functions to fetch a random row from your SP list. On the OnStart of the app, you would set a variable to a random question row. We save it to a variable, so we can change the value later - e.g. when the user wants to see another question.

     

    (1) OnStart of the app (and when you want to show another question e.g. OnSelect of a Next button):

    Set(
     varRandomQ, 
     //Change listname
     Index(
     LISTNAME, 
     //Random number between 1 and 100 -> change 100 to your last row number
     RandBetween(1,100)
     )
    )

     

    (2) Your question label would show the question of that random row:

    //Change questioncolumn
    varRandomQ.QuestionColumn

     

    (3) Validate answer

    Now I am not exactly sure what column types the options and answer columns are, but let's say Text fields for the sake of the example. In the OnSelect of those buttons you could write:

    //If you show the option text on the button itself, use Self.Text
    //Otherwise use the control you show the text in (e.g. labelName.Text)
    If(
     Self.Text = varRandomQ.AnswerColumn,
     Notify("Correct Answer!", NotificationType.Success),
     Notify("Incorrect Answer, try again.", NotificationType.Error)
    )

     

    If this solves your question, would you be so kind as to accept it as a solution.

    Thanks!

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Announcing our 2025 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for…

Paul Stork – Community Spotlight

We are honored to recognize Paul Stork as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 637 Most Valuable Professional

#2
stampcoin Profile Picture

stampcoin 570 Super User 2025 Season 2

#3
Power Apps 1919 Profile Picture

Power Apps 1919 473

Loading complete