Page 1 of 1

Checking user answer in a quiz

Posted: Wed Apr 03, 2024 4:10 am
by natalie321
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?

Re: Checking user answer in a quiz

Posted: Wed Apr 03, 2024 2:07 pm
by dunbarx
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

Re: Checking user answer in a quiz

Posted: Wed Apr 03, 2024 2:11 pm
by dunbarx
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

Re: Checking user answer in a quiz

Posted: Wed Apr 03, 2024 2:44 pm
by dunbarx
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

Re: Checking user answer in a quiz

Posted: Wed Apr 03, 2024 3:08 pm
by dunbarx
I am assuming I am correct. Try out this test stack.

Craig


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

Re: Checking user answer in a quiz

Posted: Wed Apr 03, 2024 5:48 pm
by stam
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 ;)

Re: Checking user answer in a quiz

Posted: Thu Nov 21, 2024 2:53 pm
by kakocer
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.

Re: Checking user answer in a quiz

Posted: Thu Nov 21, 2024 3:26 pm
by stam
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.

Re: Checking user answer in a quiz

Posted: Thu Nov 21, 2024 5:18 pm
by kakocer
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>

Re: Checking user answer in a quiz

Posted: Thu Nov 21, 2024 5:21 pm
by stam
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.

Re: Checking user answer in a quiz

Posted: Thu Nov 21, 2024 5:23 pm
by Klaus
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!

Re: Checking user answer in a quiz

Posted: Thu Nov 21, 2024 7:17 pm
by dunbarx
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

Re: Checking user answer in a quiz

Posted: Thu Nov 21, 2024 9:17 pm
by SparkOut
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?

Re: Checking user answer in a quiz

Posted: Fri Nov 22, 2024 12:49 pm
by richmond62
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)