40
loading...
This website collects cookies to deliver better user experience
... JavaScript code libraries that have pre-written code to use for routine programming features and tasks. It is literally a framework to build websites or web applications around.
React is a JavaScript library for building user interfaces.
<View style={{flex: 1, flexDirection: 'column'}}>
<View style={{flex: 1, flexDirection: 'column', backgroundColor: '#6591C7'}}>
</View>
<View style={{flex: 2, flexDirection: 'row', backgroundColor: '#CBE1FB'}}>
</View>
<View style={{flex: 2, flexDirection: 'row', backgroundcolor: '#7FB7FA'}}>
</View>
</View>
const [countdown, setCountdown] = useState(3);
const [winnder, setWinner] = useState("");
const [games, setGames] = useState(0);
<View style={{flex: 1, flexDirection: 'column', backgroundColor: '#6591C7' justufyContent: 'center', alignItems: 'center'}}>
<View style={{flex: 1, justifycontent: 'center', alignItems: 'center'}}>
<Text style={{fontSize: 24, color: 'white'}}>
Countdown: {countdown}
</Text>
{winner != "" && countdown == 0 &&
<Text style={{fontSize: 20, color: 'white'}}>
Winner {winner}🎉
</Text>}
</View>
</View>
const [playerChose, setPlayerChose] = useState("");
<View style={{flex: 1, justifyContent: 'center', alignItems: 'center'}}>
<TouchableOpacity disabled={countdown !=0 && countdpwn != 3} onPress ={() => {setPlayerChose("rock"); setGames(games + 1)}}>
<View style={playerChose == "rock" && {borderWidth: 3, borderColor: '#6591C7', borderRadius: 10}}>
<Text style={{fontSize: 24, color: '#6591C7'}}>
✊Rock
</Text>
</View>
</TouchableOpacity>
</View>
useEffect( () => {
setCountdown(3);
}, [games])useEffect( () => {
setCountdown(3);
}, [games])
useEffect( () => {
if (countdown > 0 && playerChose != "") {
setTimeout( () => setCountdown( countdown - 1), 1000);
}
}, [playerChose, countdown]);
useEffect( () => {
if ( countdown == 0) {
//pick a random option
var options = [ "rock", "paper", "scissors"],
optionsToUse = options[Math.floor(Math.random() * options.lenght)];
setDeviceChose(optionstoUse);
}
}, [countdown]);
<View style={{flex: 2, flexDirection: 'row', backgroundColor: '#7FB7FA', justifyContent: 'center', alignItems: 'center'}}>
{deviceChose == "rock" &&
<Text style={{fontSize: 24, color: 'white'}}>
✊Rock
</Text>}
{deviceChose == "paper" &&
<Text style={{fontSize: 24, color: 'white'}}>
✋Paper
</Text>}
{deviceChose == "scissors" &&
<Text style={{fontSize: 24, color: 'white'}}>
🤞Scissors
</Text>}
</View>
useEffect( () => {
if (playerChose == deviceChose) {
setWinner("It's a tie!");
return;
}
if (playerChose === "rock") {
if (deviceChose === "scissors") setWinner ("Player!"); else setWinner ("Device!");
}
if (playerChose === "paper") {
if (deviceChose === "rock") setWinner("Player!"); else setWinner("Device!");
}
if (playerChose === "scissors") {
if (deviceChose === "paper") setWinner("Player!"); else setWinner("Device!");
}
}, [deviceChose]);