Add two variables/numericValues?

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


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:

   when (a + b == sum) and (a * b == product) 1
   otherwise 0

But no dice. Any tips? Thank you so much in advance.

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


Thank you! You’re a lifesaver–this is going right into tomorrow’s lesson :slight_smile:

1 Like