Checking user answer in a quiz

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
natalie321
Posts: 1
Joined: Wed Apr 03, 2024 4:05 am
Contact:

Checking user answer in a quiz

Post by natalie321 » Wed Apr 03, 2024 4:10 am

Hi everyone,
I'm working on a quiz application in LiveCode. I can display the questions and allow users to select answers, but I'm having trouble checking if the chosen answer is correct and displaying feedback accordingly.
I've tried using conditional statements (if/else) but I'm not sure how to access the selected answer and compare it to the correct answer.
Can anyone point me in the right direction?

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9670
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Checking user answer in a quiz

Post by dunbarx » Wed Apr 03, 2024 2:07 pm

Hi.

So if you ask a certain question, do I assume that there is an answer already loaded somewhere? In other words, if you have a button with:

Code: Select all

on mouseUp
   answer "What is 2 + 2?" with "3" or "4" or "5"
   if it = "4" then answer "RIGHT!" else answer "Wrong"
end mouseUp
That sort of thing?

Craig
Last edited by dunbarx on Wed Apr 03, 2024 2:41 pm, edited 2 times in total.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9670
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Checking user answer in a quiz

Post by dunbarx » Wed Apr 03, 2024 2:11 pm

Much depends on how your program interacts with the user. If you pose a question, like "What is 2 + 2", how do you want the user to respond? To enter a value in a field? To click on a line in a list? To click on one button of many?

What went wrong with your own code?

Craig

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9670
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Checking user answer in a quiz

Post by dunbarx » Wed Apr 03, 2024 2:44 pm

Rereading, maybe your real issue is:
"How do I store the answer to the current question so I can compare it to whatever and however the user responds"
Is that so?

Craig

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9670
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Checking user answer in a quiz

Post by dunbarx » Wed Apr 03, 2024 3:08 pm

I am assuming I am correct. Try out this test stack.

Craig


Q & A.livecode.zip
(1.08 KiB) Downloaded 11 times

stam
Posts: 2687
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Checking user answer in a quiz

Post by stam » Wed Apr 03, 2024 5:48 pm

The reality is that the OP's question is too vague to answer.
What kind of questions are asked? how is the information structured/stored.
There are a large number of ways to tackle this - but without knowing more people will just be guessing...

Asking the right question in the right way is half the road to enlightenment ;)

Post Reply

Return to “Talking LiveCode”