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: 10305
Joined: Wed May 06, 2009 2:28 pm

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: 10305
Joined: Wed May 06, 2009 2:28 pm

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: 10305
Joined: Wed May 06, 2009 2:28 pm

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: 10305
Joined: Wed May 06, 2009 2:28 pm

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 534 times

stam
Posts: 3061
Joined: Sun Jun 04, 2006 9:39 pm

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 ;)

kakocer
Posts: 2
Joined: Thu Nov 21, 2024 2:48 pm
Contact:

Re: Checking user answer in a quiz

Post by kakocer » Thu Nov 21, 2024 2:53 pm

According to your suggestions I have made some corrections in my codes of Livecode. Now I am having only one problem that the quiz summary is not showing the correct score. It is showing the score equal to total number of questions each time. I am unable to write the code for it.

stam
Posts: 3061
Joined: Sun Jun 04, 2006 9:39 pm

Re: Checking user answer in a quiz

Post by stam » Thu Nov 21, 2024 3:26 pm

kakocer wrote:
Thu Nov 21, 2024 2:53 pm
I am unable to write the code for it.
If you are a real person and encountering genuine issues with livecode script, please post the code you've tried.

kakocer
Posts: 2
Joined: Thu Nov 21, 2024 2:48 pm
Contact:

Re: Checking user answer in a quiz

Post by kakocer » Thu Nov 21, 2024 5:18 pm

stam wrote:
Thu Nov 21, 2024 3:26 pm
kakocer wrote:
Thu Nov 21, 2024 2:53 pm
I am unable to write the code for it.
If you are a real person and encountering genuine issues with livecode script, please post the code you've tried.
<html>
< body>
<div class="start">
<h1> Welcome to Livecode </h1>
<a class="btn" href="#"> Get Started </a>
</div>

<div class="quiz">
<input type="text" class="input" />
<input type="text" class="output" />
<a class="sub" href="#" onclick="checkAnswer()"> Submit </a>
</div>

<div class="summary">
<h2> Summary Screen </h2>
<p> Congrats you scored x out of y correct ! </p>
<a class="rst" href="#" onclick="restartQuiz()"> Restart Quiz </a>
</div>

</body>
</html>

stam
Posts: 3061
Joined: Sun Jun 04, 2006 9:39 pm

Re: Checking user answer in a quiz

Post by stam » Thu Nov 21, 2024 5:21 pm

Thank you for confirming your humanity!

However you failed the LiveCode aspect of things. This is a forum for LiveCode - a cross platform development platform, and uses LiveCode Script as its language.

The code you posted is HTML - so you're not asking the question in the right place I'm afraid. You'll probably need to search elsewhere for help with that.
Last edited by stam on Thu Nov 21, 2024 5:23 pm, edited 1 time in total.

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Checking user answer in a quiz

Post by Klaus » Thu Nov 21, 2024 5:23 pm

Oooopsie!? :D
This is NO html forum, but a forum for users of the programming language "Livecode" (https://livecode.com)

Or are you using the HTML output of Livecode?
If yes, we need to take a look at the Livecode scripts, not the HTML code of the loading page!

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: Checking user answer in a quiz

Post by dunbarx » Thu Nov 21, 2024 7:17 pm

I don't speak HTML, but reading the last OP's post, it looks like there is not nearly enough "meat" in the HTML code to set up, ask a question somehow, receive an answer somehow, and then validate and report that answer. What I mean is that I think there is a LC script somewhere.

kakocer?

Craig

SparkOut
Posts: 2943
Joined: Sun Sep 23, 2007 4:58 pm

Re: Checking user answer in a quiz

Post by SparkOut » Thu Nov 21, 2024 9:17 pm

dunbarx wrote:
Thu Nov 21, 2024 7:17 pm
I don't speak HTML, but reading the last OP's post, it looks like there is not nearly enough "meat" in the HTML code to set up, ask a question somehow, receive an answer somehow, and then validate and report that answer.
SparkOut_paraphrased wrote:
Thu Nov 21, 2024 7:17 pm
What I mean is that I think there is only more generic material in that post, possibly AI generated again.

kakocer?

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10077
Joined: Fri Feb 19, 2010 10:17 am

Re: Checking user answer in a quiz

Post by richmond62 » Fri Nov 22, 2024 12:49 pm

What's the connexion between 'natalie123' and 'kakocer'?

'kakocer' is 'replying' as if they share the same identity as 'natalie123'.

No Artificial Intelligences were harmed in the production of this post. 8)

Post Reply