/
ParImpar.js
46 lines (43 loc) · 1.81 KB
/
ParImpar.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import React, { useState } from 'react'
import { Layout } from '../Layout';
export const ParImpar = () => {
const [num1, setNum1] = useState(0);
const [result, setResult] = useState("");
const handlePoP=() => {
//Reto: en vez de if utiliza el ? para devolver el mensaje de manera mas resumida
if (num1%2===0){
setResult('par ');
}
else{
setResult('impar ');
}
}
return (
<Layout>
<div className="containerNOP">
<div className="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
<h1>Ejemplo calculando numero par o impar React</h1>
{result.length>0 && (
<h4>El numero introducido es:
<p className="lead">
{result}
</p>
</h4>)}
</div>
<div className="mb-3">
<label className="form-label">Ingresar Numero</label>
<input type="text" name="num1" value={num1} onChange={(event) => { setNum1(Number(event.target.value));setResult('') }}
className="form-control" placeholder="Ingresar numero"/>
</div>
<div className="mb-3">
<button className="btn btn-primary"
onClick={() => handlePoP()}
>
Calcular
</button>
</div>
<canvas className="my-4 w-100" id="myChart" width="900" height="380"></canvas>
</div>
</Layout>
)
}