Problem with Updating Score Using List Index in Thunkable – Returns NaN


Hello Thunkable Community,

I’m working on an app where users can select countries from a list, and based on their selection, I need to update a score from another list that matches the selected country. However, I’m encountering an issue where the score is returning as NaN (Not a Number) when I try to calculate it based on the selected index.

Here’s the setup I have:

  • Country List: A list of countries (e.g., Afghanistan, Albania, Algeria, etc.).
  • Score List: A corresponding list of scores (e.g., 5, 4.12, 3.12, etc.).
  • Selected Country: I store the selected country when a list item is clicked.
  • Selected Index: I store the index of the selected country from the country list.
  • Score Update: I try to update a score variable by using the score corresponding to the selected index from the scoreList.

Issues:

  • When I click on a country from the list, it successfully sets the country and index, but the score value is returning as NaN.
  • The issue only arises when using the full list of countries, but works when there’s only a single country.
  • I’m trying to ensure the score is updated by accessing the value from the scoreList based on the index of the selected country.

I’ve checked and verified that the index and country exist in the lists. What might I be missing, and how can I ensure the score is updated correctly without getting NaN?

I have also tried a different way before this my doing it with a sheet which should be easier, apparently not! Please help.

Thanks in advance for your help!

You have a few problems:

  1. Lists should be comma-separated without spaces or quotes. So 5,3.15,3.74,2.52, etc. And Afghanistan,Albania,Algeria, etc.
  2. You can’t make a list from a text string of comma-separated values by attaching it to a list block. That just creates a list with a single item instead of multiple items. You need to use the make list from text block to do that.
  3. Don’t use duplicate list blocks. The in list block is expecting a list but you need to give it a variable that IS a list rather than another list block`. You do this by following #2 above.

Thank you for replying! However, I still have a problem.

Even though the values are correct, when I calculate the score on the next page, the numbers it’s giving me have a 0 before the score. For example, if Afghanistan = 1, it will give me 01. If Albania is 2, it will give me 02 etc. It’s not calculating correctly when I add all scores together.

I honestly don’t know what I am doing wrong, I am new in this.

Thank you in advance for helping me!


Can you post a link to your project? It will be easier for my to debug if I can see all of the blocks and screens.

https://x.thunkable.com/copy/36898c1a3f2d36f1cc75d0e4988d0d96

To better help you understand how my project works:

It consists of 3 different screens.

SCREEN 1: Simple, once you click start, it goes to Screen 2.

SCREEN 2: There are four questions that need to be answered. Question 1 and 4 are multiple choice, each checkbox has a certain value. For example: If you check box number 4 in question 1, the value will be 4. If you check check box number 3 in question 4, the value will be 2.

Questions 2 and 3 have list of countries. Each country has its own value as well. So when each one is selected, the value must be saved as well.

SCREEN 3: That’s where I calculate all values and get a final score.

My main problems were:
Sheets: I tried with Sheets but it would give me an error “undefined”.
List: With lists, I made the values work with your help but the number has a 0 before it and it doesn’t calculate properly.

Thank you!

Let’s start with Screen3:

Thunkable blocks are evaluated individually in a specific order. Even though your brain is thinking “let’s check to see if the company name is empty”, that’s not what those blocks do. They evaluate the text string “Company Name” and check to see if it has no value (null). That will never be true.

You’re asking Thunkable to create a new variable named whatever the value of FinalScore's Text is. I doubt that’s what you meant.

As for Screen2:

Although this won’t be a problem when you are testing scoring, it’s not a good way to code this:

Because if I check and then uncheck the same box, I get 8 points. What you want is a submit button that then changes the score once by checking each box’s value (true or false).

So far, I haven’t figured out why you are getting unexpected score values. It’s strange that the value I get is " 63.153.74" That’s not a real number. It looks like a list of three numbers but that would usually have commas, not periods.

Edit: FOUND IT! These blocks are causing the problem with scoring:

image

You coded it correctly to get a value from a list but… the value is going to be a text string such as “3.15” so you’re asking Thunkable to change the score by a text string. That’s going to have unpredictable results.

To fix this, you need to add zero to any text string you are using in calculations. Adding zero to a text string converts it to a number. So “3.15” + 0 = 3.15.

These are the answers I’m testing with: