# Force cells in table to be integers?

How can I require a cell in a table to be an integer value? I want students to view calculator screenshots and enter values for A and B that could have created the screenshot. For example A / B = 10.25. How can I force A and B to be integers in the table (for example 41 / 4) as opposed to decimal values (for example 102.5 / 10)?

1 Like

Thanks so much for your help. Can I do something similar in a table?

Sure! You can just use `isInteger = patterns.integer` for the pattern and then something like

``````isInteger.matches(this.cellContent(1,1)) and isInteger.matches(this.cellContent(1,2))
``````

to check if the cells match the pattern. You could also use the mod function to see if the values are divisible by 1 instead of using patterns.

I’m so sorry, but I’m still doing something wrong. Would you mind taking a look at the coding?

Thank you SO much for your help!

``````isInteger = patterns.integer
isInteger.matches(this.cellContent(1,1)) and isInteger.matches(this.cellContent(1,2)) and  isInteger.matches(this.cellContent(2,1)) and isInteger.matches(this.cellContent(2,2)) and  isInteger.matches(this.cellContent(3,1)) and isInteger.matches(this.cellContent(3,2)) and isInteger.matches(this.cellContent(4,1)) and isInteger.matches(this.cellContent(4,2))
``````

``````isIntegers.matches()
``````

that returns a boolean (true or false) - which you have to use somehow. You could try setting up an error message for each cell, something like

``````cellErrorMessage(1,1) = when not(isInteger.matches(this.cellContent(1,1)) "That's not an integer"
otherwise ""
``````
2 Likes

That is EXACTLY what I needed, thank you so much!

1 Like