# Count the number of terms

**URL:** <https://cl.desmos.com/t/count-the-number-of-terms/4005>\
**Category:** Questions\
**Tags:** patterns\
**Created:** [February 1, 2022, 3:17am UTC](https://cl.desmos.com/t/count-the-number-of-terms/4005 "2022-02-01T03:17:36Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Richard\_Punches](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/richard_punches/32/882_2.png) [@Richard\_Punches](https://cl.desmos.com/u/Richard_Punches)\
**Post date:** [February 1, 2022, 3:17am UTC](https://cl.desmos.com/t/count-the-number-of-terms/4005/1 "2022-02-01T03:17:36Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![pirsquared](https://avatars.discourse-cdn.com/v4/letter/p/4af34b/32.png) [@pirsquared](https://cl.desmos.com/u/pirsquared)\
**Post date:** [February 1, 2022, 8:36am UTC](https://cl.desmos.com/t/count-the-number-of-terms/4005/2 "2022-02-01T08:36:29Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Richard\_Punches](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/richard_punches/32/882_2.png) [@Richard\_Punches](https://cl.desmos.com/u/Richard_Punches)\
**Post date:** [February 1, 2022, 4:24pm UTC](https://cl.desmos.com/t/count-the-number-of-terms/4005/3 "2022-02-01T16:24:31Z")

</div>

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

Richard

---

<div class="post-metadata">

**Author:** ![Daniel\_Grubbs](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/daniel_grubbs/32/719_2.png) [@Daniel\_Grubbs](https://cl.desmos.com/u/Daniel_Grubbs)\
**Post date:** [February 1, 2022, 7:07pm UTC](https://cl.desmos.com/t/count-the-number-of-terms/4005/4 "2022-02-01T19:07:39Z")

</div>

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

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

```

---

<div class="post-metadata">

**Author:** ![Richard\_Punches](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/richard_punches/32/882_2.png) [@Richard\_Punches](https://cl.desmos.com/u/Richard_Punches)\
**Post date:** [February 1, 2022, 10:25pm UTC](https://cl.desmos.com/t/count-the-number-of-terms/4005/5 "2022-02-01T22:25:26Z")

</div>

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. 🙂

---

<div class="post-metadata">

**Author:** ![Richard\_Punches](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/richard_punches/32/882_2.png) [@Richard\_Punches](https://cl.desmos.com/u/Richard_Punches)\
**Post date:** [March 16, 2022, 11:50pm UTC](https://cl.desmos.com/t/count-the-number-of-terms/4005/6 "2022-03-16T23:50:24Z")

</div>

Daniel,

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

---

<div class="post-metadata">

**Author:** ![Daniel\_Grubbs](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/daniel_grubbs/32/719_2.png) [@Daniel\_Grubbs](https://cl.desmos.com/u/Daniel_Grubbs)\
**Post date:** [March 16, 2022, 11:57pm UTC](https://cl.desmos.com/t/count-the-number-of-terms/4005/7 "2022-03-16T23:57:08Z")

</div>

[https://teacher.desmos.com/computation-layer/documentation#interpreting-math](https://teacher.desmos.com/computation-layer/documentation#interpreting-math)

There’s not all the specifics, but @JayChow has made a few tutorials as well.  
Here’s from a quick [youTube search](https://www.youtube.com/results?search_query=desmos+patterns).

---

<div class="post-metadata">

**Author:** ![Richard\_Punches](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/richard_punches/32/882_2.png) [@Richard\_Punches](https://cl.desmos.com/u/Richard_Punches)\
**Post date:** [March 17, 2022, 1:10am UTC](https://cl.desmos.com/t/count-the-number-of-terms/4005/8 "2022-03-17T01:10:01Z")

</div>

Thank you for the link, Daniel.
