I'm trying to make a phone game, where user guesses the number between 1 and 100. When a button is pressed if statement should run and do some changes. Nothing althought happens. Why if statement is not executed when button is pressed?
const buttonPressed = () => {
if ({num} < {randomNum}){
message = tooLow
counter + 1
}else if ({num} > {randomNum}){
message = tooHigh
counter + 1
}else if ({num} == {randomNum}){
counter + 1
message= correct
Alert.alert('You guessed the number in'+{counter}+'guesses')
}
}
return (
<View style={styles.container}>
<View>{message}</View>
<TextInput style={styles.textinput} keyboardType='numeric'
onChangeText=
{(num) => setNum(num)} value={num}/>
<Button onPress={buttonPressed} title="Press me"/>
</View>
);
}
Aucun commentaire:
Enregistrer un commentaire