# Null and nan on my counting app

**URL:** https://community.thunkable.com/t/null-and-nan-on-my-counting-app/1849798
**Category:** Questions about Thunkable X
**Created:** [April 26, 2022, 4:02pm UTC](https://community.thunkable.com/t/null-and-nan-on-my-counting-app/1849798 "2022-04-26T16:02:31Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![rickwheeler1992](https://avatars.discourse-cdn.com/v4/letter/r/9fc29f/32.png) [@rickwheeler1992](https://community.thunkable.com/u/rickwheeler1992)
#### Post date: [April 26, 2022, 4:02pm UTC](https://community.thunkable.com/t/null-and-nan-on-my-counting-app/1849798/1 "2022-04-26T16:02:31Z")

</div>

Thanks for the help. As of now my app works great except one little bug. When I start my app for the first time, where the amount goes I get a null. If I hit a button I get a nan. It’s not a big deal because the app is just for me and if I hit reset it works fine. Although it would be nice to fix it. Here are screenshots.

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/9/d/9dd34ec75a691da655b0ab5a3f2c9affeb568c38.png)  
 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/0/3/0306875dadab04eda5358c369b8082b670d0e72f.png)  
 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/5/e/5eee36df9eb0e7a9d14d7afe110c9123218c1684.jpeg)  
 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/e/3/e3df9df24b82aeff592ae6784a4024c822fa7465.jpeg)

---

<div class="post-metadata">

### Author: ![tatiang](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/tatiang/32/55482_2.png) [@tatiang](https://community.thunkable.com/u/tatiang)
#### Post date: [April 26, 2022, 4:53pm UTC](https://community.thunkable.com/t/null-and-nan-on-my-counting-app/1849798/2 "2022-04-26T16:53:53Z")

</div>

When you use Stored variables, you have to give them a starting value.

In your screen opens blocks, do this:

If Stored variable = null  
…Set Stored variable to 0.

---

<div class="post-metadata">

### Author: ![rickwheeler1992](https://avatars.discourse-cdn.com/v4/letter/r/9fc29f/32.png) [@rickwheeler1992](https://community.thunkable.com/u/rickwheeler1992)
#### Post date: [April 26, 2022, 5:05pm UTC](https://community.thunkable.com/t/null-and-nan-on-my-counting-app/1849798/3 "2022-04-26T17:05:20Z")

</div>

@tatiang I’m not home, but I’ll try it when I get home. If I set it at zero, do I do it in the block when the screen opens? If so will it be zero every time I open the app? I want every time the app opens for it to pick up where it left off.

---

<div class="post-metadata">

### Author: ![tatiang](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/tatiang/32/55482_2.png) [@tatiang](https://community.thunkable.com/u/tatiang)
#### Post date: [April 26, 2022, 5:16pm UTC](https://community.thunkable.com/t/null-and-nan-on-my-counting-app/1849798/4 "2022-04-26T17:16:04Z")

</div>

The reason for the conditional IF is that you only set the variable to 0 if it hasn’t been set before. Once you set the variable to 0 it is no longer null. And because it’s a Stored variable, it’s saved to the device. So it gets set to 0 once and then whatever value you change that variable to, it will keep that value and the IF block will not be true ever again.

---

<div class="post-metadata">

### Author: ![rickwheeler1992](https://avatars.discourse-cdn.com/v4/letter/r/9fc29f/32.png) [@rickwheeler1992](https://community.thunkable.com/u/rickwheeler1992)
#### Post date: [April 26, 2022, 8:16pm UTC](https://community.thunkable.com/t/null-and-nan-on-my-counting-app/1849798/5 "2022-04-26T20:16:00Z")

</div>

@tatiang Sorry to be a bother. I was confused how to use the IF conditional that you were talking about. Is the top block of the screenshot right or am I way off?

 ![Screenshot (36)](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/c/5/c5314f73b1ba0b9c9790bf0d7a9bda2fbdf493ee.png)

---

<div class="post-metadata">

### Author: ![muneer](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/muneer/32/75210_2.png) [@muneer](https://community.thunkable.com/u/muneer)
#### Post date: [April 26, 2022, 8:23pm UTC](https://community.thunkable.com/t/null-and-nan-on-my-counting-app/1849798/6 "2022-04-26T20:23:39Z")

</div>

The blocks in the screen Opens are not correct.

You need to check the variable first before assigning it to any other component.

See this simple example  
 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/1/6/16ffad3ad03af62cb2846731a7b80bc9cdce71ba.png)

---

<div class="post-metadata">

### Author: ![rickwheeler1992](https://avatars.discourse-cdn.com/v4/letter/r/9fc29f/32.png) [@rickwheeler1992](https://community.thunkable.com/u/rickwheeler1992)
#### Post date: [April 26, 2022, 9:02pm UTC](https://community.thunkable.com/t/null-and-nan-on-my-counting-app/1849798/7 "2022-04-26T21:02:46Z")

</div>

@muneer thank you for trying to help me. I tried the following (screenshot) but I still get null the first time I open the new screen. I guess I’ll just live with it. It’s not a big deal, it’s just an app for myself. I was hoping I could fix it, but unfortunately I’m not the brightest when it comes to this stuff. Thank you very much.

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/c/a/ca377794accf123a31be4477e94651ffaace440f.png)

---

<div class="post-metadata">

### Author: ![muneer](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/muneer/32/75210_2.png) [@muneer](https://community.thunkable.com/u/muneer)
#### Post date: [April 26, 2022, 9:06pm UTC](https://community.thunkable.com/t/null-and-nan-on-my-counting-app/1849798/8 "2022-04-26T21:06:37Z")

</div>

I can see from the image  
 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/8/0/80260b5fa3294e2053f6ef5b371ed557007ed290.png)

You are testing `Amount 5` instead of the actual `stored variable Running Total 5`. This is the mistake.

Just follow the same example I showed you.

---

<div class="post-metadata">

### Author: ![rickwheeler1992](https://avatars.discourse-cdn.com/v4/letter/r/9fc29f/32.png) [@rickwheeler1992](https://community.thunkable.com/u/rickwheeler1992)
#### Post date: [April 26, 2022, 9:17pm UTC](https://community.thunkable.com/t/null-and-nan-on-my-counting-app/1849798/9 "2022-04-26T21:17:19Z")

</div>

@muneer thank you for being patient with me. I’m not always so bright. I misread your example and when I fixed it like you said, it works perfectly. Thank you. I’m done with my app now so I should be a bother anymore (for the time being at least). Thanks

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/0/f/0f59f292712368bce16ff80133ae10de8a6f27e8.png) [@system](https://community.thunkable.com/u/system)
#### Post date: [July 25, 2022, 9:17pm UTC](https://community.thunkable.com/t/null-and-nan-on-my-counting-app/1849798/10 "2022-07-25T21:17:54Z")

</div>

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
