# Coding question

**URL:** <https://cl.desmos.com/t/coding-question/8317>\
**Category:** Questions\
**Created:** [October 20, 2025, 7:48pm UTC](https://cl.desmos.com/t/coding-question/8317 "2025-10-20T19:48:09Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Edward\_Ankrom](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/edward_ankrom/32/8589_2.png) [@Edward\_Ankrom](https://cl.desmos.com/u/Edward_Ankrom)\
**Post date:** [October 20, 2025, 7:48pm UTC](https://cl.desmos.com/t/coding-question/8317/1 "2025-10-20T19:48:09Z")

</div>

![image](https://canada1.discourse-cdn.com/flex031/uploads/desmos/original/2X/2/2bb2c36a7b4938db0b6120aee30325e5df0c1702.jpeg)

---

<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:** [October 20, 2025, 7:49pm UTC](https://cl.desmos.com/t/coding-question/8317/2 "2025-10-20T19:49:52Z")

</div>

What is your question with the coding? The equation shown is coded by what the arrow is pointing at, although I think the slash before the “x” is unnecessary. The general syntax for a fraction as latex is `\frac{numerator}{denominator}`.

---

<div class="post-metadata">

**Author:** ![Edward\_Ankrom](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/edward_ankrom/32/8589_2.png) [@Edward\_Ankrom](https://cl.desmos.com/u/Edward_Ankrom)\
**Post date:** [October 20, 2025, 9:14pm UTC](https://cl.desmos.com/t/coding-question/8317/3 "2025-10-20T21:14:19Z")

</div>

![image](https://canada1.discourse-cdn.com/flex031/uploads/desmos/original/2X/7/7d5501d9b0d523c429dc0650d84f9ade23547bcd.png)

I entered this equation and the check box will check green but stays an X.

---

<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:** [October 20, 2025, 9:16pm UTC](https://cl.desmos.com/t/coding-question/8317/4 "2025-10-20T21:16:02Z")

</div>

Can you share a link to your activity so I can look at the rest of your code? Specifically, I’d guess it has something to do with `valid`.

---

<div class="post-metadata">

**Author:** ![NTMDev](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/ntmdev/32/7141_2.png) [@NTMDev](https://cl.desmos.com/u/NTMDev)\
**Post date:** [October 21, 2025, 1:40am UTC](https://cl.desmos.com/t/coding-question/8317/5 "2025-10-21T01:40:29Z")

</div>

Am I wrong or doesn’t `simpleFunction` need an `identifier` for the variables in it?

`simpleFunction(“y=\frac{5}{2}x-2”,”y”,”x”)`

---

<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:** [October 21, 2025, 4:09am UTC](https://cl.desmos.com/t/coding-question/8317/6 "2025-10-21T04:09:09Z")

</div>

> [@NTMDev](#):
>
> doesn’t `simpleFunction` need an `identifier` for the variables in it?

If there is no identifier, `simpleFunction()` defaults to in terms of x. An equation like `y=\frac{5}{2}x-2` is treated as `f(x)=\frac{5}{2}x-2`, so no variable arguments are necessary. Conversely, `2y=\frac{5}{2}x-2` is an implicit equation and can’t be treated as a function because there is no isolated variable.

---

<div class="post-metadata">

**Author:** ![NTMDev](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/ntmdev/32/7141_2.png) [@NTMDev](https://cl.desmos.com/u/NTMDev)\
**Post date:** [October 21, 2025, 11:12am UTC](https://cl.desmos.com/t/coding-question/8317/7 "2025-10-21T11:12:35Z")

</div>

Oh. Then I don’t see any problem here!

---

<div class="post-metadata">

**Author:** ![Edward\_Ankrom](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/edward_ankrom/32/8589_2.png) [@Edward\_Ankrom](https://cl.desmos.com/u/Edward_Ankrom)\
**Post date:** [October 21, 2025, 4:27pm UTC](https://cl.desmos.com/t/coding-question/8317/8 "2025-10-21T16:27:18Z")

</div>

> [@NTMDev](#):
>
> simpleFunction(“y=\frac{5}{2}x-2”,”y”,”x”)

I tried this and got a lot of red flags.

---

<div class="post-metadata">

**Author:** ![Edward\_Ankrom](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/edward_ankrom/32/8589_2.png) [@Edward\_Ankrom](https://cl.desmos.com/u/Edward_Ankrom)\
**Post date:** [October 21, 2025, 4:31pm UTC](https://cl.desmos.com/t/coding-question/8317/9 "2025-10-21T16:31:09Z")

</div>

> [@Daniel\_Grubbs](#):
>
> y=\frac{5}{2}x-2

This works for non fractions: f1 = simpleFunction(`y=-5x+3`)

but I cant code to correct the problems y = 5/2x - 2

I have tried various versions of what people have listed?

---

<div class="post-metadata">

**Author:** ![Edward\_Ankrom](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/edward_ankrom/32/8589_2.png) [@Edward\_Ankrom](https://cl.desmos.com/u/Edward_Ankrom)\
**Post date:** [October 21, 2025, 4:39pm UTC](https://cl.desmos.com/t/coding-question/8317/10 "2025-10-21T16:39:37Z")

</div>

This is the line of code that works for non fraction answers.

f1 = simpleFunction(‘`y=-5x+3`’)

---

<div class="post-metadata">

**Author:** ![Edward\_Ankrom](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/edward_ankrom/32/8589_2.png) [@Edward\_Ankrom](https://cl.desmos.com/u/Edward_Ankrom)\
**Post date:** [October 21, 2025, 4:44pm UTC](https://cl.desmos.com/t/coding-question/8317/11 "2025-10-21T16:44:55Z")

</div>

Here is my activity

> **[Ankrom-Solving Literal Equations • Activity by Amplify Classroom](https://classroom.amplify.com/activity/68f66146e585f0ee457f0f66?utm_campaign=share&utm_content=activity)**
>
> Practicing Literal Equations

---

<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:** [October 21, 2025, 4:57pm UTC](https://cl.desmos.com/t/coding-question/8317/12 "2025-10-21T16:57:41Z")

</div>

The reason it’s not working is the `xTerm` pattern is specifying a number:

```auto
xTerm = p.anyOf(X, p.product(p.number,X) , p.negative(X))

```

Updating it to the following should allow fractional slopes:

```auto
pFraction = p.fraction(p.integer, p.integer)
xTerm = p.anyOf(
   X, 
   p.product(p.anyOf(p.number, p.negative(pFraction), pFraction),X),
   p.negative(X))

```

(returns are just for readability, but aren’t necessary)

---

<div class="post-metadata">

**Author:** ![Edward\_Ankrom](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/edward_ankrom/32/8589_2.png) [@Edward\_Ankrom](https://cl.desmos.com/u/Edward_Ankrom)\
**Post date:** [October 21, 2025, 5:31pm UTC](https://cl.desmos.com/t/coding-question/8317/13 "2025-10-21T17:31:40Z")

</div>

Thanks for that info,

First time doing an activity builder like this.

What lines do I type this on?

Just type over the current line?

---

<div class="post-metadata">

**Author:** ![NTMDev](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/ntmdev/32/7141_2.png) [@NTMDev](https://cl.desmos.com/u/NTMDev)\
**Post date:** [October 21, 2025, 5:48pm UTC](https://cl.desmos.com/t/coding-question/8317/14 "2025-10-21T17:48:48Z")

</div>

Huh? That doesn’t make sense. It should work, but as @Daniel_Grubbs said it is unnecessary

Edit: Oh, you need “`” things

---

<div class="post-metadata">

**Author:** ![NTMDev](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/ntmdev/32/7141_2.png) [@NTMDev](https://cl.desmos.com/u/NTMDev)\
**Post date:** [October 21, 2025, 5:49pm UTC](https://cl.desmos.com/t/coding-question/8317/15 "2025-10-21T17:49:48Z")

</div>

What’s `fraction`, `anyOf`, `product`, or `negative`? Are the `sources`/functions for lists?

---

<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:** [October 21, 2025, 6:15pm UTC](https://cl.desmos.com/t/coding-question/8317/16 "2025-10-21T18:15:46Z")

</div>

Those are definitions for patterns, which can be used in an indeterminate number of combinations to analyze and parse latex expressions.

Here’s [an intro series](https://cl.desmos.com/t/pattern-matching-basics/5522).

---

<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:** [October 21, 2025, 6:31pm UTC](https://cl.desmos.com/t/coding-question/8317/17 "2025-10-21T18:31:44Z")

</div>

> [@Edward\_Ankrom](#):
>
> What lines do I type this on?
> 
> Just type over the current line?

Sorry, missed this one. Yes, just replace the `xTerm` line with the new set of code I provided. Poaching and editing other folks’ code is a great way to jump in and learn!

---

<div class="post-metadata">

**Author:** ![Edward\_Ankrom](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/edward_ankrom/32/8589_2.png) [@Edward\_Ankrom](https://cl.desmos.com/u/Edward_Ankrom)\
**Post date:** [October 21, 2025, 6:34pm UTC](https://cl.desmos.com/t/coding-question/8317/18 "2025-10-21T18:34:52Z")

</div>

Thanks

I got that work.

I do have another question.

When the first value is an integer and the second is a fraction, do I need to adjust that line?

For example if the answer is y = 2x - 3/2

or if the answer has 2 fractions, such as y= 1/2x+ 3/2

---

<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:** [October 21, 2025, 6:38pm UTC](https://cl.desmos.com/t/coding-question/8317/19 "2025-10-21T18:38:12Z")

</div>

Ah yes. Similarly, your `constantTerm` is defined as `p.number` , which includes integers, decimals, and mixed numbers, but not fractions. This is because the fraction pattern is more accurately a rational expression, rather than a number. So we have to similarly include options:

```auto
constantTerm = p.anyOf(p.number, p.negative(pFraction), pFraction)

```

---

<div class="post-metadata">

**Author:** ![Edward\_Ankrom](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/edward_ankrom/32/8589_2.png) [@Edward\_Ankrom](https://cl.desmos.com/u/Edward_Ankrom)\
**Post date:** [October 21, 2025, 7:38pm UTC](https://cl.desmos.com/t/coding-question/8317/20 "2025-10-21T19:38:08Z")

</div>

If you switch the question to solve for x, do you simply change all xs to ys and vice versa

with all the coding?

Ed
