I am practicing making the game of stone paper and scissors in react native at the moment it works well but my problem is that the variable "result" does not show me the result of the current game if it is a tie or not if it does not show me the result of the game above, for example if I choose stone and the app also chooses stone it is tie but it does not show me however if I choose stone again and the app chooses paper the result variable shows tie which is from the previous game when its not a tie
this is the code
const RockPaperScissors = () => {
const [userOption, setUserOption] = useState("user")
const [computerOption, setComputerOption] = useState("computer")
const [result, setResult] = useState("")
const options = ["paper", "rock", "scissors"]
const rockOption = () => {
let choice = Math.floor(Math.random()*3)
setComputerOption(options[choice])
}
const resultRock = () => {
setUserOption("rock")
if (computerOption == userOption){
setResult("tie")
} else {
setResult("no tie")
}
}
const combineRock = () => {
rockOption()
resultRock()
}
const RenderComputer = () => {
if (computerOption == "paper") {
return (
<FontAwesome name="hand-paper-o" size={70} color="black" />
)
}
if (computerOption == "rock") {
return (
<FontAwesome name="hand-rock-o" size={70} color="black" />
)
}
if (computerOption == "scissors") {
return (
<FontAwesome name="hand-scissors-o" size={70} color="black" />
)
}
}
return (
<View style={styles.container} >
<Text style={styles.title} >
Rock - Paper - Scissors
</Text>
<View style={styles.containerGame} >
<View style={styles.computer} >
<Text>Computer Option</Text>
<RenderComputer/>
</View>
<Text>Result: {result}</Text>
<View style={styles.user} >
<Text>Your Option</Text>
<FontAwesome name="hand-rock-o" size={70} color="black" onPress={combineRock}/>
{/* <FontAwesome name="hand-paper-o" size={70} color="black" onPress={rockOption}/>
<FontAwesome name="hand-scissors-o" size={70} color="black" onPress={rockOption}/> */}
</View>
</View>
</View>
)
}