This feels so simple that I’m almost pre-embarrassed for asking, but…How do you add two numbers in CL? I have a table that gets two numbers from students, and I want to write a script that checks if those numbers add and multiply to a given pair of values (yes, we’re starting factoring), and return a “success” image if they do.
I’ve got:
sum = 7
product = 12
number("a"):table2.cellNumericValue(1,1)
number("b"):table2.cellNumericValue(1,2)
And I want a number c that evaluates to 1 when the sum & product of a & b are correct, and 0 otherwise. I basically want to write:
number("c"):
when (a + b == sum) and (a * b == product) 1
otherwise 0
But no dice. Any tips? Thank you so much in advance.
https://teacher.desmos.com/activitybuilder/custom/5eb0f127f7748708150fd545
CL doesn’t do calculations without using numericValue or simpleFunction, so 2 methods to your calculations. It’ll be easier to set variables ‘a’ and ‘b’ instead of variables in the graph to calculate in CL, or you can calculate ‘c’ in the graph more easily.
Method 1 (CL doesn’t use double = for comparisons either):
a= table2.cellNumericValue(1,1)
b= table2.cellNumericValue(1,2)
c=when numericValue("${a}+${b}")=sum and numericValue("${a}*${b}")=product 1 otherwise 0
Method 2 (still define variables a and b as above):
sumF=simpleFunction("x+y","x","y")
productF=simpleFunction("x*y","x","y")
c=when sumF.evaluateAt(a,b)=sum and productF.evaluateAt(a,b)=product 1 otherwise 0
Method 3 (define numbers a and b as you initially did) in the graph itself:
c={a+b=7 {a*b=12}:1,0}
1 Like
Thank you! You’re a lifesaver–this is going right into tomorrow’s lesson
1 Like