Correct Check for Numeric Value

I am brand new to CL and am trying to take another teacher’s activity and have students see “Correct!” or “Incorrect. Try again!” when submitting a value. I tried using code from Jennifer White’s self-checking slides, but can’t get it to work with my existing activity.

Here’s my activity:

Would love some help! I feel like it should be easy, but just can’t get it to work.

Which slide? Where do you want it to say correct/incorrect?

Some basics. You’ll need to name the input component in order to refer to it in another component. For myself, I do a standard whatever type of component it is and the slide number (Ex: Input5, or Graph2).

To change the content of a note based on a submitted answer, I’d do something like this:

#this is a little trick if you want to copy slides, so you only need to change component names in one place
input=Input5
content: when input.submitted
#I’m nesting conditionals so it’ll only check when the submit button is clicked
(when input.numericValue=20 “:+1:Correct!”
otherwise “:warning:Incorrect. Try again.”)
otherwise “Your instructions.”

Also note if you’re checking numericValue from the input it needs to be set to Math input not Text.

Thanks! I figured it out about 10 minutes after sending this. It was the “Math input” and not text that was causing issues.

Appreciate it!

@Daniel_Grubbs

I’m trying to code mixed numbers/fractions in my activity. Would you be able to help?

I would just need help coding slide 5 - trying to code the answer as 2 2/3. Here’s my activity:

I assume you meant you wanted to check that an answer is given as a mixed fraction.

I’d use something like this (in the math input component):

checkValue = numericValue("\abs(${this.latex}-(8/3))")<=0.01
checkMixed = countNumberUsage(this.latex,2)=2 and countNumberUsage(this.latex,3)=1
correct: checkValue and checkMixed

checkValue just checks if the value is correct within 0.01, so 2.67, 8/3, or 2 2/3 would output true. checkMixed uses countNumberUsage to see if the number 2 is used twice, and 3 once. I split into two parts so you could give specific feedback if the answer isn’t a mixed fraction but is the correct value.

Let me know if there are any other questions about the code.

Can you explain what each line means please
input?

this.latex is the math input. (You can use “this” to refer to the component your code is in, instead of needing to name it.)

checkValue is checking that the difference between the student input and the correct answer (8/3) is less than 1/100.

checkMixed is determining whether the correct numbers are used in the answer.

countNumberUsage takes an input (this.latex) and checks how many times a number occurs, the second parameter.

Here the correct answer is 2 2/3, so we want to see two 2’s and one 3. The second parameter does not accept negative values. So, checkMixed would be true for 2 2/3, -2 2/3, -2 -2/3, etc. but checkValue will account for ambiguity.

1 Like

Thank you Daniel. I used the CL for my slide and it worked exactly how I wanted it, thank you.