I need help coding my math input to accept only numerical values and no variables, it does not only have to be integers (it can be any real number)…
Hello!
I believe this should work:
errorMessage: when isUndefined(this.numericValue) "Please enter a number, not a variable." otherwise ""
warning: errorMessage
I just started CL, so I’m not 100% sure if this works. If it doesn’t then I don’t have much to say. You should contact specialists like @Daniel_Grubbs at that point.
Here is an example of a math response accepting only numbers.
https://teacher.desmos.com/activitybuilder/custom/683e87c0c31de062d22850d8?utm_campaign=share&utm_content=activity
Inputs allow characters, with some limitations, following a expression to be treated as units. So an entry of 3cm
or 1+2cm
would each have a defined numericValue of 3.
@Alexander_3691 's method is probably the best way to deny this. If you want to allow numbers and expressions, you could alternatively use isUndefined(simpleFunction(this.latex,``))
where the simpleFunction()
is essentially a function with no arguments.
Oh… so my example wasn’t the most efficient, or something else?
I’m pretty curious in this topic as well, and I have to ask what exactly simpleFunction
does.
Thanks Daniel for helping me out for answering this issue
Your method actually won’t work because this.numericValue
is defined with trailing letters which it treats as units. simpleFunction()
is a function. It can take one or more arguments. The first is a latex expression or an equation written in the form y=
(any variable except x
) or as a function (e.g. f(x)=
).
f1 = simpleFunction(`3x-2`) #valid
f2 = simpleFunction(`f(x)=3x-2`) #valid
f3 = simpleFunction(`3x-2=y`) #invalid
If there is no second argument as in the samples above, the function is in terms of x
. For functions in terms of other variables, or more than one variable, they need to be defined. Or you can define the function to have no arguments.
f1 = simpleFunction(`3x-2y`,`x`,`y`)
f2 = simpleFunction(this.latex, ``) #variables in this.latex render this undefined.
simpleFunction
can be used to define a function in graph CL using the function(``):
sink, or to use for calculations in the CL via .evaluateAt()
.
Ohhhh! I see. I thought isUndefined
would just stop you from entering characters other than numbers (this.numericValue
), but seems like from what you said it would just cause an error instead of just stopping the user from entering the variables.
I wasn’t aware of simpleFunction
, so I learned something too
Also, what’s the number()
sink (just asking this when I have a chance)?
It defines a variable in the graph. You can do it explicitly, but may as well define it in the graph, or reference other CL variables. CL sinks of any type will overwrite graph definitions.
number(`a_1`): 5
number(`a_2`): input1.numericValue
Oh ok! That’s cool… it’s like a variable not in CL, but in the Desmos graphing calculator. Interesting why it’s a sink not a source… I feel like it would be more efficient if we did this.number(variableName, value)
And just while your at it, could you check this post out?