# How to create nutrition app with ocr scanner?

**URL:** <https://community.thunkable.com/t/how-to-create-nutrition-app-with-ocr-scanner/1113955>\
**Category:** Questions about Thunkable X\
**Created:** [February 21, 2021, 5:28pm UTC](https://community.thunkable.com/t/how-to-create-nutrition-app-with-ocr-scanner/1113955 "2021-02-21T17:28:00Z")\
**Posts on this page:** 20\
**Page:** 6

<div class="post-metadata">

**Author:** ![celebytes20212iy4](https://avatars.discourse-cdn.com/v4/letter/c/ba8739/32.png) [@celebytes20212iy4](https://community.thunkable.com/u/celebytes20212iy4)\
**Post date:** [March 8, 2021, 10:02pm UTC](https://community.thunkable.com/t/how-to-create-nutrition-app-with-ocr-scanner/1113955/102 "2021-03-08T22:02:17Z")

</div>

Could you just explain to me in a brief post of what I need to remove or change and then I can rewatch some other thunkable tutorials? Do I need to remove everything under the “set app variable response” and redo that whole part, or just change what checks in the “if” block?

---

<div class="post-metadata">

**Author:** ![celebytes20212iy4](https://avatars.discourse-cdn.com/v4/letter/c/ba8739/32.png) [@celebytes20212iy4](https://community.thunkable.com/u/celebytes20212iy4)\
**Post date:** [March 9, 2021, 12:31am UTC](https://community.thunkable.com/t/how-to-create-nutrition-app-with-ocr-scanner/1113955/103 "2021-03-09T00:31:19Z")

</div>

Or could you set up a zoom meet sometime to help me? Because I need to finish this project by this weekend, but it could take a couple of days to fix the errors as well.

---

<div class="post-metadata">

**Author:** ![celebytes20212iy4](https://avatars.discourse-cdn.com/v4/letter/c/ba8739/32.png) [@celebytes20212iy4](https://community.thunkable.com/u/celebytes20212iy4)\
**Post date:** [March 9, 2021, 7:38pm UTC](https://community.thunkable.com/t/how-to-create-nutrition-app-with-ocr-scanner/1113955/104 "2021-03-09T19:38:56Z")

</div>

When would you be free to explain what I need to fix? I can do zoom too

---

<div class="post-metadata">

**Author:** ![celebytes20212iy4](https://avatars.discourse-cdn.com/v4/letter/c/ba8739/32.png) [@celebytes20212iy4](https://community.thunkable.com/u/celebytes20212iy4)\
**Post date:** [March 9, 2021, 11:11pm UTC](https://community.thunkable.com/t/how-to-create-nutrition-app-with-ocr-scanner/1113955/105 "2021-03-09T23:11:59Z")

</div>

Could you please let me know where to restart or fix so I can get this finished in a couple days? I need to finish this by friday so I can fix the errors over the weekend.

---

<div class="post-metadata">

**Author:** ![celebytes20212iy4](https://avatars.discourse-cdn.com/v4/letter/c/ba8739/32.png) [@celebytes20212iy4](https://community.thunkable.com/u/celebytes20212iy4)\
**Post date:** [March 10, 2021, 1:04am UTC](https://community.thunkable.com/t/how-to-create-nutrition-app-with-ocr-scanner/1113955/106 "2021-03-10T01:04:10Z")

</div>

I watched a couple more tutorials and added these blocks. If this is correct should I add this for each letter grade(A, B, C, D, E)?

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/9/f/9f7c8d53cb67df03afd8a57b553871accf51f278.png)  
I forgot to put “product” in the bottom block.

---

<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:** [March 10, 2021, 6:30am UTC](https://community.thunkable.com/t/how-to-create-nutrition-app-with-ocr-scanner/1113955/107 "2021-03-10T06:30:03Z")

</div>

I don’t have time to help you over Zoom this week. I was hoping you had a teacher who was able to offer you support.

Your “if” block checks to see if there is an error. Then, if there is an error, the “do” section of that block runs all of those other blocks. But if there is not an error, none of those blocks in the screenshot will run.

I don’t understand the positive and negative points and how they relate to the grade of A to E. So I can’t comment on whether or not what you have is correct. But if it works then, yes, you can set it up that way for each letter grade.

---

<div class="post-metadata">

**Author:** ![celebytes20212iy4](https://avatars.discourse-cdn.com/v4/letter/c/ba8739/32.png) [@celebytes20212iy4](https://community.thunkable.com/u/celebytes20212iy4)\
**Post date:** [March 10, 2021, 8:23pm UTC](https://community.thunkable.com/t/how-to-create-nutrition-app-with-ocr-scanner/1113955/108 "2021-03-10T20:23:47Z")

</div>

If the positive and negative points won’t work, then what property can I use to find the food grade?

---

<div class="post-metadata">

**Author:** ![celebytes20212iy4](https://avatars.discourse-cdn.com/v4/letter/c/ba8739/32.png) [@celebytes20212iy4](https://community.thunkable.com/u/celebytes20212iy4)\
**Post date:** [March 10, 2021, 8:30pm UTC](https://community.thunkable.com/t/how-to-create-nutrition-app-with-ocr-scanner/1113955/109 "2021-03-10T20:30:33Z")

</div>

I’m creating an app that scans a food barcode, and after reading the barcode the user will receive a food grade (A, B, C, D, E) or nutriscore. I have the barcode scanner and the web api set up, but I don’t know what properties to use to display the nutriscore of that specific food object.

This is my database: [https://world.openfoodfacts.org/api/v0/product/04963406](https://world.openfoodfacts.org/api/v0/product/04963406)  
These are the blocks I have so far:

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/4/4/44276852a18b55dc235db1561405a8819b3883b1.png)

---

<div class="post-metadata">

**Author:** ![celebytes20212iy4](https://avatars.discourse-cdn.com/v4/letter/c/ba8739/32.png) [@celebytes20212iy4](https://community.thunkable.com/u/celebytes20212iy4)\
**Post date:** [March 11, 2021, 12:54am UTC](https://community.thunkable.com/t/how-to-create-nutrition-app-with-ocr-scanner/1113955/110 "2021-03-11T00:54:15Z")

</div>

I am trying to keep it simple by only using the carbohydrates. I followed some tutorials and this is what I have. When I try it it just says that I have an error with the blocks. Can you please help me find and fix the the error?

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/e/f/efba13f561a6c1c6b903a432ec3a8c677287e725.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:** [March 11, 2021, 1:36am UTC](https://community.thunkable.com/t/how-to-create-nutrition-app-with-ocr-scanner/1113955/111 "2021-03-11T01:36:54Z")

</div>

First of all avoid name duplicating. Even if the development platform can handle it, it is very confusing for People.

Try using a different name for carbohydrates\_100g variable because the same name is used as a property in your object.

Second, use debug labels to know the output in every step of your code and to be certain that it is the intended/expected outcome.

Lastly, can you explain the `else if` condition you are testing? I don’t see any test unless the property is of a boolean type.

---

<div class="post-metadata">

**Author:** ![celebytes20212iy4](https://avatars.discourse-cdn.com/v4/letter/c/ba8739/32.png) [@celebytes20212iy4](https://community.thunkable.com/u/celebytes20212iy4)\
**Post date:** [March 11, 2021, 1:31pm UTC](https://community.thunkable.com/t/how-to-create-nutrition-app-with-ocr-scanner/1113955/112 "2021-03-11T13:31:27Z")

</div>

For the else/if statements I want the amount of carbohydrates in that specific food. Then the number of carbs in each food is what I’m using to place it in a certain category (Like how healthy the food is).

---

<div class="post-metadata">

**Author:** ![celebytes20212iy4](https://avatars.discourse-cdn.com/v4/letter/c/ba8739/32.png) [@celebytes20212iy4](https://community.thunkable.com/u/celebytes20212iy4)\
**Post date:** [March 11, 2021, 1:38pm UTC](https://community.thunkable.com/t/how-to-create-nutrition-app-with-ocr-scanner/1113955/113 "2021-03-11T13:38:31Z")

</div>

Is this how you use the debug command?

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/6/e/6e6de65baa8550f5852d51a52f429126f34b7fee.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:** [March 11, 2021, 8:04pm UTC](https://community.thunkable.com/t/how-to-create-nutrition-app-with-ocr-scanner/1113955/114 "2021-03-11T20:04:08Z")

</div>

Why are you using `random integer` in your `if conditions` this will make your app unpredictable.

I advise you to read and educate yourself on the programming logic and how to construct conditions in programs.

---

<div class="post-metadata">

**Author:** ![celebytes20212iy4](https://avatars.discourse-cdn.com/v4/letter/c/ba8739/32.png) [@celebytes20212iy4](https://community.thunkable.com/u/celebytes20212iy4)\
**Post date:** [March 11, 2021, 8:16pm UTC](https://community.thunkable.com/t/how-to-create-nutrition-app-with-ocr-scanner/1113955/115 "2021-03-11T20:16:15Z")

</div>

The carbs in each food have to be between specific numbers to be healthy/unhealthy. I couldn’t find another block that could equal the resulting number to be between two numbers.

---

<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:** [March 11, 2021, 9:27pm UTC](https://community.thunkable.com/t/how-to-create-nutrition-app-with-ocr-scanner/1113955/116 "2021-03-11T21:27:37Z")

</div>

Whatever your reason is, it is programmatically wrong and lead to unexpected results.

---

<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:** [March 11, 2021, 10:26pm UTC](https://community.thunkable.com/t/how-to-create-nutrition-app-with-ocr-scanner/1113955/117 "2021-03-11T22:26:41Z")

</div>

I know that you want a simple fix for everything but there are a lot of problems with the way you set up your code. I can’t solve it all for you and some of this is just taking the time to learn to program. The reality of coding is that if you change one little thing, it then affects everything else. So you have fixed one or two problems from earlier but then added new problems that you didn’t have before because you moved things around or added blocks.

Some of this is basic programming like the fact that the “else if” section of a block only happens if the condition is false but the condition itself has to be a true/false statement; or realizing that a variable does not have a value until you give it a value using the “set” block. Those are things you learn over time by starting with a very simple programming task and lots of trial and error.

It seems like you’re in a hurry to get everything done by this weekend which is somewhat unfortunate because you’ve picked one of the absolute hardest features of Thunkable (Web APIs) to begin with and it’s not quick to learn. At all. But I’m a broken record at this point.

Perhaps this diagram will be helpful to point you in some directions to get the problems resolved:

 ![errors](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/e/9/e9d315305c0be5e7696996c1a7c005d2ff5eca2a.png)

---

<div class="post-metadata">

**Author:** ![celebytes20212iy4](https://avatars.discourse-cdn.com/v4/letter/c/ba8739/32.png) [@celebytes20212iy4](https://community.thunkable.com/u/celebytes20212iy4)\
**Post date:** [March 11, 2021, 10:39pm UTC](https://community.thunkable.com/t/how-to-create-nutrition-app-with-ocr-scanner/1113955/118 "2021-03-11T22:39:34Z")

</div>

Okay. Thank you for helping me out! I’ll fix those mistakes.

I had a quick question. I know I would set the variable carbs to get the json response, but what would I set for the variable “message”?

---

<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:** [March 11, 2021, 10:48pm UTC](https://community.thunkable.com/t/how-to-create-nutrition-app-with-ocr-scanner/1113955/119 "2021-03-11T22:48:08Z")

</div>

I think @muneer’s suggestion was to use labels to display intermediate steps in your code. So instead of running the entire set of blocks and wondering why it doesn’t work, you can debug your code by adding “set label’s text to” blocks every so often and checking values that you are getting from blocks (e.g. from JSON, etc.). You can even put Wait blocks and/or Vibrate blocks in so that you know where you are in the code when something does/does not work.

This is what I tend to do in my own projects:

> [@Debugging in Thunkable X (Video)](https://community.thunkable.com/t/debugging-in-thunkable-x-video/849471):
>
> I thought I’d share a process I use for debugging my projects. It involves creating a function that can be used over and over throughout the code blocks in order to help determine where things are going wrong, whether or not certain blocks are ever triggering, and what the values of several variables are. Here’s a screenshot of what I’ve set up: The real power comes from being able to quickly change the delay (and even set it to 0 seconds) or just remo…

---

<div class="post-metadata">

**Author:** ![celebytes20212iy4](https://avatars.discourse-cdn.com/v4/letter/c/ba8739/32.png) [@celebytes20212iy4](https://community.thunkable.com/u/celebytes20212iy4)\
**Post date:** [March 11, 2021, 11:58pm UTC](https://community.thunkable.com/t/how-to-create-nutrition-app-with-ocr-scanner/1113955/120 "2021-03-11T23:58:46Z")

</div>

Is there still an error with the way this is set up? When I live test it says there is something wrong with the blocks.

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

---

<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:** [March 12, 2021, 12:08am UTC](https://community.thunkable.com/t/how-to-create-nutrition-app-with-ocr-scanner/1113955/121 "2021-03-12T00:08:48Z")

</div>

Yes, it’s still not correct. Please watch my API/JSON tutorial video to see how to set up the “get object from JSON” and “get property of object” blocks and how my if/else blocks are structured.

[Previous page](https://community.thunkable.com/t/how-to-create-nutrition-app-with-ocr-scanner/1113955.md?page=5)

[Next page](https://community.thunkable.com/t/how-to-create-nutrition-app-with-ocr-scanner/1113955.md?page=7)
