Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!
I try to program a learning app. There are 60 questions with text answers. This could look like this:
"What are the colors?"
Answers is
"Blue and red"
So I have an label with the question and a text field for the answer. So the person answers the quest and I like the app to look at the textfield if it conatins the words "blue" and red".
put "red" into theAnswer
if theAnswer is among the words of field myField
then answer "Great"
else answer "False"
Put this only work with one word. I like to check is there are both words "red" and "blue" in the answer text field. But I d not know how. There could be up to 20 words I have to check. Some with AND and some with OR operators? Is there a way to achieve this?
function isRightAnswer mySolution, userAnswer
repeat for each word W in mysolution
-- every word W must be in the user's answer
if W is not among the words of userAnswer then return false
end repeat
return true
end isRightAnswer
on mouseUp
put "A B C" into mySolution
put "B C" into userAnswer
if isRightAnswer( mySolution, userAnswer) then
answer "Great!"
else
answer "Too bad :("
end if
end mouseUp
HTH,
Thierry
! SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
thank you both for your fast help. One more Question
Thierry your code look fine to me and works also. But it looks like "is among" is not right for my use case.
Example:
If mySolution is balls and the user write ball its wrong. So I thought I usw your code snippet with contains .. but this doesnt work. I used it this way:
function isRightAnswer mySolution, userAnswer
repeat for each word W in mysolution
-- every word W must be in the user's answer
if userAnswer contains not W then return false
end repeat
return true
end isRightAnswer
but now all is a valid answer and I do not know why
function isRightAnswer mySolution, userAnswer
repeat for each word W in mysolution
-- every word W must be in the user's answer
if userAnswer contains W then
-- do nothing
else
return false
end if
end repeat
return true
end isRightAnswer
If all words are in the answer the function will return true when repeat ends, if not it will return false and exit repeat. I dont think "contains not" i supposed to work, that why you get those results.