In a Math response box, I enter this script to check the answer is correct (in the example, the correct answer is 25):
answer = this.numericValue
correct: answer=25
How can I check the correctness of a string? For context, it’s a science activity about genes, and the possible answers are BBHH, BBHh, BBhh, BbHH, BbHh, Bbhh, bbHH, bbHh, and bbhh. If the correct answer is BbHh, how do I check they entered the correct answer (BbHh)?
I imagine I can’t use a Math Response box, and I need to use a Free response box. As you can see, upper/lower case letters are important, so I don’t have to worry about the students writing “Answer” vs “answer”. It has to be exactly BbHh. How can i do it?
You can use a textbox input and do something like: check = this.content ="BbHh"
It works, but you won’t get a checkmark on the Teacher Dashboard because Desmos - rightly or wrongly - doesn’t like textual responses being “correct” or “incorrect” for textual responses.
Alternatively you could simply code this as a latex response for a math input like so:
Thanks. I totally understand why Desmos doesn’t like to correct textual responses because there is an infinite number of ways you can write a correct answer, but my case is justified because the question says: “write the genotype”, and students are expected to write a four-letter word consisting of two B’s and two H’s and all possible combinations of upper and lower case. I ended up using a latex response, which allows me to see the correct/incorrect responses on the Teacher Dashboard. Howpefully nobody will write “BbHh.” or “It is BbHh.”. I’ll clarify that they are expected to write four letters and nothing else.
You could check the form and use an error message.
p = patterns
var = p.anyOf(p.literal(`B`),p.literal(`b`),p.literal(`H`),p.literal(`h`))
# This is a product pattern with exactly 4 factors
validEntry = p.product(var, var, var, var).matches(this.latex)
# This alternative product pattern can have an indefinite number of factors,
# but is checking there are 4
#OR validEntry = p.product(p.repeat(var)).parse(this.latex).term1.n = 4
errorMessage:
when isBlank(this.latex) or validEntry ""
otherwise "Write a genotype using only four letters."
You can update the “var” line for new alleles. If you need more letters, extend the first version, or change the number on the second version.