# Help with CL code to respond to multiple answers

**URL:** <https://cl.desmos.com/t/help-with-cl-code-to-respond-to-multiple-answers/3308>\
**Category:** Questions\
**Tags:** validation, correctness\
**Created:** [May 20, 2021, 10:39am UTC](https://cl.desmos.com/t/help-with-cl-code-to-respond-to-multiple-answers/3308 "2021-05-20T10:39:15Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![tarnold](https://avatars.discourse-cdn.com/v4/letter/t/c5a1d2/32.png) [@tarnold](https://cl.desmos.com/u/tarnold)\
**Post date:** [May 20, 2021, 10:39am UTC](https://cl.desmos.com/t/help-with-cl-code-to-respond-to-multiple-answers/3308/1 "2021-05-20T10:39:15Z")

</div>

Hi , am doing a set of questions which self mark , give a correct or incorrect response to the student and then total up and provide a summary.

So far so good.

My code for a slid which has a single answer is:

**Note code** :(note1)  
content: “{message} {feedback}”

message = “What is the 9th multiple of 15?”

feedback = when ans1.submitted and ans1.numericValue=135 “\n\n\n​✅Good work ! !”  
when ans1.submitted “\n\n\n​❌Wrong answer. Please try again.”  
otherwise “”

**Maths Answer Box code:** - (ans1)  
disableEvaluation: true

check1 = when this.numericValue=135 1 otherwise 0  
correct: check1=1

However I am trying to do the same sort of thing for a slide that will have multiple answer , in this case list the factors of 49 in ascending order.

I am using a table instead for the student to input the answers and want the feedback to be based on ALL the answers being correct - however I can’t seem to get this to work. I am struggling with getting the feedback code in the note to work and also how to give check2(the variable that I use to total up the marks) a value of 1 when all items in the table are correct.

Here is my code:

What should the equivalent feedback code in order to work?

Here is my code for the table:  
t=table2  
cellContent(1,2): when t.cellNumericValue(1,1)=1 “✅” OTHERWISE “N”  
cellContent(2,2): when t.cellNumericValue(2,1)=7 “✅” OTHERWISE “N”  
cellContent(3,2): when t.cellNumericValue(3,1)=49 “✅” OTHERWISE “N”

isCorrect = t.cellNumericValue(1,1)=1 and t.cellNumericValue(2,1)=7 and t.cellNumericValue(3,1)=49  
#check2 = isCorrect 1 otherwise 0  
correct: isCorrect

---

<div class="post-metadata">

**Author:** ![tarnold](https://avatars.discourse-cdn.com/v4/letter/t/c5a1d2/32.png) [@tarnold](https://cl.desmos.com/u/tarnold)\
**Post date:** [May 20, 2021, 11:03am UTC](https://cl.desmos.com/t/help-with-cl-code-to-respond-to-multiple-answers/3308/2 "2021-05-20T11:03:57Z")

</div>

Sorted it. **Heres my code for the table:**

t=table2  
cellContent(1,2): when t.cellNumericValue(1,1)=1 “✅” OTHERWISE “N”  
cellContent(2,2): when t.cellNumericValue(2,1)=7 “✅” OTHERWISE “N”  
cellContent(3,2): when t.cellNumericValue(3,1)=49 “✅” OTHERWISE “N”

isCorrect = t.cellNumericValue(1,1)=1 and t.cellNumericValue(2,1)=7 and t.cellNumericValue(3,1)=49

correct: isCorrect

check2= when isCorrect 1 otherwise 0

**and heres the Note feedback code:**

content: “{message} {feedback}”

message = “List the factors of 49 in ascending order”

feedback = when table2.script.check2=1 “\n\n\n✅Good work ! !”  
when table2.script.check2=0 “\n\n\n❌Wrong answer. Please try again.”  
otherwise “”

---

<div class="post-metadata">

**Author:** ![cwinske](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/cwinske/32/3106_2.png) [@cwinske](https://cl.desmos.com/u/cwinske)\
**Post date:** [May 20, 2021, 4:28pm UTC](https://cl.desmos.com/t/help-with-cl-code-to-respond-to-multiple-answers/3308/3 "2021-05-20T16:28:58Z")

</div>

This line of code can be deleted as it is the the same thing as isCorrect: `check2= when isCorrect 1 otherwise 0`

Then for the feedback variable, you can use this instead:

```auto
feedback = when table2.script.isCorrect “\n\n\n✅Good work ! !”
when not(table2.script.isCorrect) “\n\n\n❌Wrong answer. Please try again.”
otherwise “”

```

You could include a button press as well, if you’d like, otherwise the feedback will always be displayed.

---

<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:** [May 20, 2021, 9:34pm UTC](https://cl.desmos.com/t/help-with-cl-code-to-respond-to-multiple-answers/3308/4 "2021-05-20T21:34:34Z")

</div>

Just something for the future. Whenever you’re checking some kind of correctness multiple times, it can clean things up a little to make a variable for it. Makes debugging or changing values a little easier:

```auto
t=table2

c1= t.cellNumericValue(1,1)=1
c2= t.cellNumericValue(2,1)=7
c3= t.cellNumericValue(3,1)=49

cellContent(1,2): when c1 "✅" OTHERWISE “❌”
cellContent(2,2): when c2 "✅" OTHERWISE “❌”
cellContent(3,2): when c3 "✅" OTHERWISE “❌”

isCorrect = c1 and c2 and c3

correct: isCorrect

```

---

<div class="post-metadata">

**Author:** ![SandiG](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/sandig/32/1895_2.png) [@SandiG](https://cl.desmos.com/u/SandiG)\
**Post date:** [May 21, 2021, 5:00pm UTC](https://cl.desmos.com/t/help-with-cl-code-to-respond-to-multiple-answers/3308/5 "2021-05-21T17:00:23Z")

</div>

Modular code best code.

---

<div class="post-metadata">

**Author:** ![tarnold](https://avatars.discourse-cdn.com/v4/letter/t/c5a1d2/32.png) [@tarnold](https://cl.desmos.com/u/tarnold)\
**Post date:** [May 22, 2021, 7:59am UTC](https://cl.desmos.com/t/help-with-cl-code-to-respond-to-multiple-answers/3308/6 "2021-05-22T07:59:37Z")

</div>

Hi,could you explain or give me some link to look at . Thanks

---

<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:** [May 22, 2021, 3:29pm UTC](https://cl.desmos.com/t/help-with-cl-code-to-respond-to-multiple-answers/3308/7 "2021-05-22T15:29:09Z")

</div>

Not sure who you’re responding to. I think @SandiG was referring to my code. Also, you can share your own activity link and many times people are willing to edit a copy of your activity directly instead of needing to copy paste typed examples.

My example would just replace everything up to your correct sink from your original post. You can replace “check2=1” with “isCorrect” in your feedback code.

---

<div class="post-metadata">

**Author:** ![tarnold](https://avatars.discourse-cdn.com/v4/letter/t/c5a1d2/32.png) [@tarnold](https://cl.desmos.com/u/tarnold)\
**Post date:** [May 24, 2021, 9:37am UTC](https://cl.desmos.com/t/help-with-cl-code-to-respond-to-multiple-answers/3308/8 "2021-05-24T09:37:43Z")

</div>

Thanks. Heres the activity (hope I’ve shared it correctly)

> **[Draft 2 Skills Check FA1.1 • Activity Builder by Desmos](https://teacher.desmos.com/activitybuilder/custom/60ab620da4e615086f6104d9)**
>
> by TArnold

I’m trying to get the first slide to act as a summary so the teacher can quickly see what topics are causing issues. Each topic has 2 queations so I’ve put 2 columns in which show this for the questions.

I would like there to be an N in the cells if no attempt has been made on that question. Is this possible?

I did consider giving subtotals for each topic but couldn’t get that to work.

---

<div class="post-metadata">

**Author:** ![tarnold](https://avatars.discourse-cdn.com/v4/letter/t/c5a1d2/32.png) [@tarnold](https://cl.desmos.com/u/tarnold)\
**Post date:** [May 24, 2021, 11:52am UTC](https://cl.desmos.com/t/help-with-cl-code-to-respond-to-multiple-answers/3308/9 "2021-05-24T11:52:00Z")

</div>

Hi thanks.

I’m using check2 as a type of global variable that I can call on in a results page on slide 1.

---

<div class="post-metadata">

**Author:** ![SandiG](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/sandig/32/1895_2.png) [@SandiG](https://cl.desmos.com/u/SandiG)\
**Post date:** [May 24, 2021, 8:08pm UTC](https://cl.desmos.com/t/help-with-cl-code-to-respond-to-multiple-answers/3308/10 "2021-05-24T20:08:28Z")

</div>

To my knowledge, global variables aren’t a thing for CL. All variables are part of their individual components i.e. `component1.script.var1`.

---

<div class="post-metadata">

**Author:** ![SandiG](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/sandig/32/1895_2.png) [@SandiG](https://cl.desmos.com/u/SandiG)\
**Post date:** [May 24, 2021, 8:12pm UTC](https://cl.desmos.com/t/help-with-cl-code-to-respond-to-multiple-answers/3308/11 "2021-05-24T20:12:51Z")

</div>

I don’t think there’s a way to initialize every cell without specifying each in turn and I don’t know of a way to do loops with CL.

So my solution was to add another possible state for each cell

```auto
cellContent(1,3): when ans1.script.check1=1 "✅" when ans1.submitCount=0 "N" OTHERWISE "❌"

```

---

<div class="post-metadata">

**Author:** ![Aethir](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/aethir/32/2767_2.png) [@Aethir](https://cl.desmos.com/u/Aethir)\
**Post date:** [May 24, 2021, 11:31pm UTC](https://cl.desmos.com/t/help-with-cl-code-to-respond-to-multiple-answers/3308/12 "2021-05-24T23:31:25Z")

</div>

I _think_ you want your first slide to function like an amped up version of slide 12 in this activity:

> **[Systems of Equations (Ch. 5) Study Guide • Activity Builder by Desmos](https://teacher.desmos.com/activitybuilder/custom/60a7e031dc7160754adf15b2)**
>
> by ARIEL ORCUTT

Note that it works pretty much like SandiG suggested - individual checks.

For checking whether students have made an attempt: for Q1, for example, you could see if the math input is blank AND if the submit count is 0. That won’t catch if they wrote something, erased it, and never hit submit, but it’ll catch every other case, I think.

---

<div class="post-metadata">

**Author:** ![tarnold](https://avatars.discourse-cdn.com/v4/letter/t/c5a1d2/32.png) [@tarnold](https://cl.desmos.com/u/tarnold)\
**Post date:** [May 26, 2021, 11:55am UTC](https://cl.desmos.com/t/help-with-cl-code-to-respond-to-multiple-answers/3308/13 "2021-05-26T11:55:49Z")

</div>

Thanks , I’ve used that and it works well. However on eof the slides has a table where the student has to list the factors of a number. I can get the summary table to show a tick or a cross depending onthe students answer but as there is not submit button I can’t get it to display an N if the student hasn’t attempted it. Is there someway of me checking on the slide whether the cell has not had any data entered and returning a value I can use inthe summary table?

This is the code I have on slide 2 which checks the table cells:

t=table2

c1= t.cellNumericValue(1,1)=1  
c2= t.cellNumericValue(2,1)=5  
c3= t.cellNumericValue(3,1)=25

cellContent(1,2): when c1 “✅” OTHERWISE “N”  
cellContent(2,2): when c2 “✅” OTHERWISE “N”  
cellContent(3,2): when c3 “✅” OTHERWISE “N”

check2 = when c1 and c2 and c3 1 otherwise 0

correct: check2=1

This is the code on the summary table whch works when I am using a maths answer box and submit button:

cellContent(1,3): when ans1.script.check1=1 “✅” when ans1.submitCount=0 “N” OTHERWISE “❌”  
cellContent(1,4): when table2.script.check2=1 “✅” when table2.submitCount=0 “N” OTHERWISE “❌”

cellContent(2,3): when ans3.script.check3=1 “✅” when ans3.submitCount=0 “N” OTHERWISE “❌”  
cellContent(2,4): when ans4.script.check4=1 “✅” when ans4.submitCount=0 “N” OTHERWISE “❌”

---

<div class="post-metadata">

**Author:** ![Aethir](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/aethir/32/2767_2.png) [@Aethir](https://cl.desmos.com/u/Aethir)\
**Post date:** [May 26, 2021, 12:20pm UTC](https://cl.desmos.com/t/help-with-cl-code-to-respond-to-multiple-answers/3308/14 "2021-05-26T12:20:08Z")

</div>

_Maybe_ the best you can do for that is isBlank:

[isBlank documentation](https://teacher.desmos.com/computation-layer/documentation#function:isBlank)

Something like this, perhaps?

```auto
cellContent(1,2): when not(isBlank(t.cellContent(1,1)) and not(c1) "Attempted"

```

---

<div class="post-metadata">

**Author:** ![SandiG](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/sandig/32/1895_2.png) [@SandiG](https://cl.desmos.com/u/SandiG)\
**Post date:** [May 28, 2021, 12:32am UTC](https://cl.desmos.com/t/help-with-cl-code-to-respond-to-multiple-answers/3308/15 "2021-05-28T00:32:46Z")

</div>

I think this is your best bet @tarnold. Though I think as written, that code would prevent students from entering anything? CL locks cells that have their content specified @Aethir, so wouldn’t that overwrite the student value when they enter it?

I would create a note component and put a checksum variable in there that displays a check when the whole table is correct to your specifications.

Here’s an example of what I mean from one of my activities earlier this week. Answers are specified in the table CL along with overall screen correctness, but answers are referenced and displayed by the notes with ✅ and ❌.

> **[table check example • Activity Builder by Desmos](https://teacher.desmos.com/activitybuilder/custom/60b0390d4fcc006c5db0c3b5)**
>
> by Glenn Laursen

---

<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:** [May 28, 2021, 3:07pm UTC](https://cl.desmos.com/t/help-with-cl-code-to-respond-to-multiple-answers/3308/16 "2021-05-28T15:07:41Z")

</div>

If you’re wanting “N/A” or something instead of a ✅❌ before they attempt a question, I usually use this for a table:

```auto
cellContent(1,2): when isBlank(cellContent(1,1)) or cellHasFocus(1,1) "N/A"
when c1 "✅"
otherwise "❌"

```
