I have a table that has text entries and I would like the table to calculate the number of letters in each word

I have run this activity and students often count the number of letters wrong and I’d like it to populate the number of letters per word after they enter the word.

I have the total column working to calculate the total letters

Desmos doesn’t have much in the way of string manipulation functions, including string lengths - so I don’t think there’s a solution in this case. However, given that there’s not a mathematical gain to students manually typing in the words - and even if Desmos could calculate string length, there’s nothing to stop them typing the word in incorrectly - it might just be worth them entering the word number instead, and having a list of the word lengths that it can refer to.

For instance, in a graph component you’d have something like L=[13,3,7,7,2,6,8,2,7,.....] to represent the lengths. Then in the table component, you could have something like cellContent(1,2): graph.numberList(`L`).elementAt(cellNumericValue(1,1)). Then you can be sure that the totals gained are genuine representations of the sample.

Thank you so much for your feedback. I teach stats and this activity actually has 2 parts, the first is to manually “self-select” words (which per cognitive research) your eye is drawn to longer words, so I want to make the connection of students focused on the words, not the number associated for the initial part,
next I have them use random number generator to select 10 numbers and then they calculate the average word length using random sampling and the conclusion is illustrated that self-selection is biased and consistently over estimates the average word length. So for the first part of the activity, I wouldn’t want to just have them write down the number. For the second part I have then write down the number and the word so I very much appreciate your suggested approach.

I was trying to implement it, but had some difficulty. Would I use a “script” to define the list? and then be able to reference it across components? I wasn’t sure how to define it within the table. I do already have that list defined in a future slide (pg7) but just not sure how to integrate the suggest CL in my activity

Sounds like a great and interesting activity!

So you’d need to define the list of word lengths in a graph component. This would just be something like L_ength=[13,3,7,7,2,6,8,2,7,.....] with all 125 lengths defined. (You can paste lists into Desmos by copying them from a spreadsheet so if you have the lengths of words there, you can save yourself a manual entry job).

Then, in the CL, you can find the word length for any given word by using graph.numberList(`L_ength`).elementAt(...) where … is the word number from 1 to 125. So if the word length was going to go into table cell (1,2) and students were entering the number of the word in table cell (1,1), you could use cellContent(1,2): graph.numberList(`L_ength`).elementAt(cellNumericValue(1,1)) to populate this automatically.

I love a good lesson on cognitive biases! Thanks for sharing.

One additional workaround is to use pattern parsing. Desmos can look at the word ‘the’ and interpret it as the product of the three variables t * h * e, and pattern parsing quickly gives you the number of terms multiplied together. The code looks like

p = patterns
Prod = p.product(p.repeat(p.expression))
n = Prod.parse(this.latex).term1.n #the number of letters in this.latex

I added in the appropriate lines on screens 3 & 8 here to count word lengths. I also made one other small change on screen 3 so that the dot plot no longer includes a dot for the bottom (total) row of the table. I hope that helps :slight_smile:

Thank you so much!!! I was having trouble making the other suggestion work. I am not great with CL, especially beyond basics :slight_smile:

Thank you again Ian, I am wondering if there is any way I can populate the second table column 1 with the 10 random numbers from RNG ?

I am also wondering if you have any recommendations for documentation for CL beyond what DESMOS has? I have a hard time trying to get data from different slides / components I am more familiar with more traditional coding and get tripped up trying to follow DESMOS doc

Happy to help! The same copy of your activity I shared before is updated with the numbers from RNG automatically populated in the second table. The table looks at the randomly generated numberList in RNG (it’s called s_{withoutReplacement}) and picks out each random number using elementAt.

With regards to documentation, here are some resources I’ve found useful. Just in case you haven’t encountered some of them, I’m mentioning Desmos-made resources, too.

  • Another user, @Daniel_Wekselgreene, has been gracious enough to share an entire tutorial document he created (thank you!). It walks step-by-step through some common uses of CL.
  • In the official Desmos CL documentation, I really like the ‘sandbox’ area they provide to experiment with provided code. You can access the sandbox by clicking the ‘Try It’ button next to any example code:
  • The Desmos YouTube channel features several videos that walk through building an activity from the ground up. There are also recordings of several intro to CL webinars.

Finally, I’ve learned a lot of what I know about CL by searching this support forum every time I run into a new problem :slight_smile: I hope at least one of these resources comes in handy for you. If other folks reading have other go-to resources, please share those, too!

Thank you so much for everything! I really appreciate the help and the pointers to resources. I think were I have the issues is just putting the pieces together properly at this point. I knew I needed RNG but not the elementAT and defining the variable ‘random’ I will definitely check out the sandbox and the tutorials!