https://snack.expo.io/@miralis/bad-apple Check pressNumber. I want to Alert.alert("Nice work!") when "if" returns true, and ("Try again!") when it returns false, but Alert.alert() doesn't work.
-
1Upon trying the link you provided, it seems to work. What exactly is the problem? – blankart Jul 1 '20 at 0:28
It seems to work like @blankart said, I guess just because you declare a random num
and then you can't catch the correct number each time. Just change the num to a real number like this and input it. You can go into the true statement.
PS:You could console out the num and number to check the original statement.
const [number, setNumber] = useState();
const pressNumber = () => {
const num = (Math.random() * 1).toFixed(); //random each time is different.
//if(num == number) {
if(number == 5) { // and then input 5 is the correct to nice work.
console.log("Nice work!");
Alert.alert("Nice work!")
}
else {
console.log(num) // console the num
console.log(number) // console the number
console.log("Try again!");
Alert.alert("Try again!")
}
}
-
Could you explain where is not useful or there is any problem let you downvote? – 高鵬翔 Jul 1 '20 at 2:06