# Count the number of terms

Hello CL Community,

I have a randomly generated order of operations problem that has 1200 combinations. Is there CL code that can count the number of terms in a math input answer? I want to be able to compare the value of the input to the value of an answer generated in a graph, but have found that if students just type in the original expression it is marked correct. I want the value to match and have a single term. I have used countNumberUsage before, but in this case, I cannot account for all of the combinations.

Thanks,
Richard

Will the terms all be numeric? If so, then `countNumberUsage(...)=1` should do the trick - this will discard any expression with multiple numeric terms because something like 3+9*15 will have countNumberUsage(…) of 3.

If potentially they could be including algebraic terms then you can also test `isDefined(this.numericValue)` - this should yield false for something like 5+x etc. where `countNumberUsage` would still count 1.

If this doesn’t help, can you give some examples of what you would and would not want to allow?

This is very helpful. I’ll try it later today. Thanks for the response.

Richard

You can also use a pattern match to verify it’s a number:

``````check= patterns.number.matches(this.latex)
``````

Daniel,
I like this solution. I am just looking for the final number. This tests if they put in an expression. For example, if the answer is 30 and a student enters 25+5, it marks it incorrect because it is an expression vs a number. That is all I need. Students will be showing their work with pencil and paper and just entering the final answer on the Desmos. Desmos grades the final answer and I give points for correct work.

Daniel,

Where can I find documentation about the code for pattern matching?

https://teacher.desmos.com/computation-layer/documentation#interpreting-math

There’s not all the specifics, but @Jay has made a few tutorials as well.
Here’s from a quick youTube search.

Thank you for the link, Daniel.