# How to check units

I want to check a students input for correctness including units.(answer is 126 cm squared)

This is what I am trying but its not working:

disableEvaluation: true

check20= when this.latex =`126{\cm^2}` 1 otherwise 0
correct: check20=1

It might not totally fix the problem, but you should have 126\cm^{2}

1 Like

Youâ€™re unlikely to be able to check units in this way.
Desmos does not handle units well(at all really) in the Math Input field.

You might try asking a follow on question about units, but keep the units out of this particular field.

2 Likes

You can check by turning the student input into a function in terms of c and m and evaluating for a few pairs of values:

``````target= simpleFunction(`126cm^2`,"c","m")
ans= simpleFunction(this.latex,"c","m")
check20= target.evaluateAt(2,3)=ans.evaluateAt(2,3)
and target.evaluateAt(3,2)=ans.evaluateAt(3,2)
``````
3 Likes

Fixed now, but forgot the variables in the second function.

1 Like

You could include a hidden multiple choice option for units separately that appears after theyâ€™ve submitted their numerical answer. Not pretty, but solid workaround.

3 Likes

Hi thanks. Iâ€™ve used your code which works when I specify the object ans20. however I use check20 on slide 1 to get a total score using this code:

total=numericValue(`\${ans1.script.check1}+\${table2.script.check2}+\${ans3.script.check3}+\${ans4.script.check4}+\${ans5.script.check5}+\${ans6.script.check6}+\${ans7.script.check7}+\${ans8.script.check8}+\${ans9.script.check9}+\${ans10.script.check10}+\${ans11.script.check11}+\${ans12.script.check12}+\${ans13.script.check13}+\${ans14.script.check14}+\${ans15.script.check15}+\${ans16.script.check16}+\${ans17.script.check17}+\${ans18.script.check18}+\${ans19.script.check19}+\${ans20.script.check20}`)
content: â€śYou got \${total} out of 20 questions correct.â€ť

and am now getting the error message:

â€śUnexpected type in latex interpolation : booleanâ€ť

previously this code was working.

Without looking into your activity, I can see one potential problem:

numericValue needs this format:

``````numericValue("\${variable}+\${variable}")
``````

Note the quotes around the whole expression!

The code in the () brackets is actually already enclosed by`` - they just donâ€™t show up when copied over. When I delete
`+\${ans20.script.check20}`

the code works. The problem started to occur when I changed the code on slide 20 (as Daniel suggested) that checks for correctness of both number and units of length.

Ah, ok!

You are using Danielâ€™s code on slide 20 now, right? Your original check20 was a number, but Danielâ€™s is a boolean, which would explain your problem. You could just add another variable to add instead, like

``````thingToAdd = when check20 1 otherwise 0
``````
1 Like

Yes, seems to be expecting number. Will try that thanks

Thanks Aether , that solved it. Was getting myself confused that just because I was giving a value of 1 or 0 to check20 previously that it was boolean!! DUH

2 Likes

Yes. Given that is practically impossible for students to correctly enter metric units into a maths field, since metric unit symbols must always be in upright case (and separated from the numeric part by a space or product dot), itâ€™s better to not have them enter them at all.

Units is an area where students commonly stuff up - I really wish Desmos and other platforms would put some serious thought in how we can do this better.

1 Like