Now to shows such an alert, React Native has got us covered, from React Native we can import alert and
that's also not a component we use but instead, an object where we can call a native API, where we can call
a native feature. So here where we return if one of these conditions is met and therefore we're not having
a valid number, there we can call alert.alert and now throw an alert which you can configure as described
here. You can set a title, you can add a message and you can also add buttons and some general options.
Now the title could be invalid
number, the message string could be number has to be a number between 1 and 99.
Buttons then is an array of alert buttons,
what you add here are simply Javascript objects where each object can have a certain style, a text and
a press, so a click handler basically and I will add a text here where I simply say okay, where I then define
a style and style here is one of three text values,
it's not a style you defined with a stylesheet,
instead it's one of these three predefined style identifiers.
It's either a cancel style, default or destructive,
this changes the colour and presentation here and I'll give this destructive as a style and I'll also
add my own press handler where I point at the reset input handler because I want to reset the user input
if it was invalid anyways. With that the alert is configured and this alert will now be shown if the
input is invalid
here. Let's give it a try and save this
and if I click confirm here, I actually get not a number,
we'll have to fix that but if I enter 0 here, now I get this alert with the okay button and if I click
it, this is reset and we're good
but let's make sure that we also get this if we have not a number, if chosen number is not a number
and the reason for that is that this check won't work in Javascript,
instead you have a special isNaN function which you wrap your value around
and now this will check for you if this is not a number and if that returns true, we make it into this
if block and therefore would throw this alert,
so now submitting an empty value also is invalid.
So that's important,
use is not a number instead of that equality check.
So now we're checking for this, valid values are still allowed
and with that, let's work on this confirmation presentation so that we can soon also enter the next stage
and start a game.