I’m trying to keep track of statistics such as longest streak of correct answers on a page (2) for random questions.
I have it working in a graph that I copied from someone else’s code, but I don’t understand how to follow or modify it - the graph just throws me and I don’t have the time to learn right now. So I thought I’d recreate it in code which I do understand and can follow better, but computational layer is not like any code I’ve ever written. So I’m having some issues here also.
It seems that the action button code is not acting like an event handler (the code runs as soon as the page loads rather than waiting until I actually click the button. The code in question is in the btnCheck1 component. The code that isn’t working is currentStreak and currentMax. I have modified it several times from my original in an attempt to circumvent the issue. Originally I was trying to capture current streak, but that wasn’t working, so I decided to capture how much to remove from the score, but that’s not working either. When I look at the variable values, it seems that the captures happen before the action button is pressed.
You are correct that the code runs when the page loads (it also doesn’t load for thumbnails in case you ever wonder why your preview doesn’t match).
Here’s a method using alternately hidden buttons (rather than disabling) with score, total number of questions answered, current streak and longest streak. You can update btn1 to use whatever component you like with the correctness defined in that component.
A side thing I noticed in your below CL. when-otherwise conditionals don’t work in the same way a switch would in other coding languages. It will follow the order given and output once a condition is met, so below the “and noOfStars >=#” becomes redundant.
Thanks. This I can follow and modify. I do have one question though. In the filter for the list el is being used. It’s not a variable and I can’t find it in the documentation. I think I know what it is doing, but I’m not sure and where can I find things like this in the documentation?
You may consider lists still beta, so the documentation is not quite there yet. Here is an article from a colleague, and in this example of a summary table I provided in another thread, I have comments in my code.
Basically, the syntax for most list functions is list.functionName((el, i) => output/condition) where “el” is the current element, and the optional argument “i” is the current index, which you might use to reference corresponding elements in other lists. You can use any variable name you like for “el” and “i”.