# Labels - can I make labels both dynamic and conditional?

I am making an activity to covery Equations of Circles. Students use the sliders to create the circle and the equation appears floating above as a dynamic label. However, I can’t figure out how to make subtracting a negative appear as addition in the equation (see the screenshot attached). Is there a way that I can make my label conditional, so that I could change the form based on whether h and/or k are positive or negative. I’ve attached a screen shot of my current work. Thanks for any help.

You could control the conditionals with CL.

https://teacher.desmos.com/computation-layer/documentation#component:input/graph:sink:pointLabel

Yeah there are a few CL tricks you could do here. I might try:

``````hWithSign = when h < 0 `-\${h}` when h > 0 `+\${h}` otherwise ``
kWithSign = when k < 0 `-\${k}` when k > 0 `+\${k}` otherwise ``
pointLabel("L"): `(x\${hWithSign})^2 + (y\${kWithSign})^2 = \${r2}`
``````

I think you’ve got your conditionals flipped, and that wouldn’t fix `- -`

``````hWithSign = when h > 0 `-\${h}` when h < 0 `+\${numericValue(`-\${h}`)}` otherwise ``
kWithSign = when k > 0 `-\${k}` when k < 0 `+\${numericValue(`-\${k}`)}` otherwise ``
pointLabel("L"): `(x\${hWithSign})^2 + (y\${kWithSign})^2 = \${r2}`
``````

(Instead of the numericValues, you could make variables in the graph for `|h|` and `|k|`.)

Thanks to both of you. I’ve managed to build the code in the CL window of the graph and it works great except that when h or k is less than zero I end up with ± in front of the number. I’ve been trying to somehow add in absolute values, but again my lack of programming skills in this language (Latex?) is showing. Attached is the code I have added in the CL window for the graph. I need to change the value of x in the statement `+\${x}` to its absolute value (or simply reverse its sign) the definition of hWithSign (same for kWithSign). Thanks for additional help. I’m learning a lot here. Mine won’t do that (with the numericValue).

Currently `hWithSign` does exactly the same thing you had before. By using `\${x}`, if it’s negative it will dislpay `+-h`. You need to NOT use `\${x}`. I didn’t use absolute value in my code, but same result since it’s negative of a negative.

OK, with all your help, here is the code I came up with and it works PERFECTY (even drops the parenthesis when h or k=0). Lesson learned (amongst many): if you copy/paste code from a CL window to this blog, all the ` symbols get dropped.

Thank you both for the help. I appreciate your time and expertice.

1 Like