From the course: React Native Essential Training

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Computing dynamic values where needed

Computing dynamic values where needed - React Native Tutorial

From the course: React Native Essential Training

Start my 1-month free trial

Computing dynamic values where needed

- [Instructor] It's time for us to write code to determine if the game is won or lost. This means that while we're tapping on numbers we want to calculate the sum of the selected numbers. This sum is going to affect the game status. The game status can be one of three values. It can be the currently playing game status or it could be won, or it could be lost. The thing is this game status can be computed so we don't really need to put it on the state. So what I'm going to do is I'm going to create a new function here and call it game status. And the goal of this function is to compute the game status at any point. So the first thing that we need is the sum of selected number. Let's put that in a variable, call that sum selected. We can compute the sum of selected numbers from the selected IDs that we put on the state. Cause every time we select a number here we place its index ID on the state. In fact this selected…

Contents