# Correct Check for Numeric Value

**URL:** <https://cl.desmos.com/t/correct-check-for-numeric-value/760>\
**Category:** Questions\
**Tags:** validation, correctness\
**Created:** [March 24, 2020, 7:37pm UTC](https://cl.desmos.com/t/correct-check-for-numeric-value/760 "2020-03-24T19:37:53Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Laura\_Morey](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/laura_morey/32/545_2.png) [@Laura\_Morey](https://cl.desmos.com/u/Laura_Morey)\
**Post date:** [March 24, 2020, 7:37pm UTC](https://cl.desmos.com/t/correct-check-for-numeric-value/760/1 "2020-03-24T19:37:53Z")

</div>

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:

> **[Block Geometry - NHS Mario 64 Volume: Prisms, Pyramids, Spheres, and Cylinders...](https://classroom.amplify.com/activity/5e7a4ffe26937f0cb7149013)**
>
> Find the volume of rectangular prisms, triangular prisms, spheres, and cylinders found in Mario 64.

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

---

<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 24, 2020, 8:04pm UTC](https://cl.desmos.com/t/correct-check-for-numeric-value/760/2 "2020-03-24T20:04:02Z")

</div>

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 “👍Correct!”  
otherwise “⚠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.

---

<div class="post-metadata">

**Author:** ![Laura\_Morey](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/laura_morey/32/545_2.png) [@Laura\_Morey](https://cl.desmos.com/u/Laura_Morey)\
**Post date:** [March 24, 2020, 8:06pm UTC](https://cl.desmos.com/t/correct-check-for-numeric-value/760/3 "2020-03-24T20:06:45Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![Olivia\_Husbands](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/olivia_husbands/32/960_2.png) [@Olivia\_Husbands](https://cl.desmos.com/u/Olivia_Husbands)\
**Post date:** [August 4, 2020, 12:54am UTC](https://cl.desmos.com/t/correct-check-for-numeric-value/760/4 "2020-08-04T00:54:26Z")

</div>

@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:

> **[AS - Grade 6 Unit 1 Lesson 9 • Activity Builder by Desmos](https://teacher.desmos.com/activitybuilder/custom/5f25c21e20b58b21d556e8f5)**
>
> by Olivia Husbands

---

<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:** [August 4, 2020, 5:38pm UTC](https://cl.desmos.com/t/correct-check-for-numeric-value/760/5 "2020-08-04T17:38:56Z")

</div>

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):

```auto
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.

---

<div class="post-metadata">

**Author:** ![Maria\_Frias\_Staff\_Ca](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/maria_frias_staff_ca/32/2020_2.png) [@Maria\_Frias\_Staff\_Ca](https://cl.desmos.com/u/Maria_Frias_Staff_Ca)\
**Post date:** [January 26, 2021, 5:18am UTC](https://cl.desmos.com/t/correct-check-for-numeric-value/760/6 "2021-01-26T05:18:15Z")

</div>

Can you explain what each line means please  
input?

---

<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:** [January 26, 2021, 8:23am UTC](https://cl.desmos.com/t/correct-check-for-numeric-value/760/7 "2021-01-26T08:23:44Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Pamela\_Knapp](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/pamela_knapp/32/1749_2.png) [@Pamela\_Knapp](https://cl.desmos.com/u/Pamela_Knapp)\
**Post date:** [January 26, 2021, 2:32pm UTC](https://cl.desmos.com/t/correct-check-for-numeric-value/760/8 "2021-01-26T14:32:58Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Annemarie\_Newell](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/annemarie_newell/32/3764_2.png) [@Annemarie\_Newell](https://cl.desmos.com/u/Annemarie_Newell)\
**Post date:** [August 27, 2022, 7:12pm UTC](https://cl.desmos.com/t/correct-check-for-numeric-value/760/10 "2022-08-27T19:12:18Z")

</div>

I’m trying to code a Note that says if a student’s Math Input value is correct based on a function that is based on the coordinates of a draggable point. In other words, the value that should be typed in the Math Input will not always be the same numeric value and depends on where the student dragged their point in the graph.

They should be calculating the distance between the two points. How can I verify that their number is correct based on the values in the table from the dragged point?

> **[What's the best path? • Activity Builder by Desmos](https://teacher.desmos.com/activitybuilder/custom/630a57d916d1783960a07662)**
>
> This activity prompts students to use concepts of Distance and Midpoints to choose the best paths for different scenarios. Students can use the Distance Formula or Midpoint Formulas to calculate certain measurements and locations on the coordinate...

---

<div class="post-metadata">

**Author:** ![Daniel\_Wekselgreene](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/daniel_wekselgreene/32/1819_2.png) [@Daniel\_Wekselgreene](https://cl.desmos.com/u/Daniel_Wekselgreene)\
**Post date:** [August 28, 2022, 3:18am UTC](https://cl.desmos.com/t/correct-check-for-numeric-value/760/11 "2022-08-28T03:18:35Z")

</div>

The easiest way is to calculate the distance inside of the graph. Pass the input value into the graph as well. And then compare them to see if they are equal (or close to equal). Use that to set a boolean variable. Then refer to that in the CL to display correctness. Here is what that could look like:

> **[\[Copy of\] What's the best path? • Activity Builder by Desmos](https://teacher.desmos.com/activitybuilder/custom/630adb50ccdaa40677eca3b6)**
>
> This activity prompts students to use concepts of Distance and Midpoints to choose the best paths for different scenarios. Students can use the Distance Formula or Midpoint Formulas to calculate certain measurements and locations on the coordinate...
