Advertisement
IlanZiin

#043 EXERFCÍCIO PRÁTICO TABUADA DA MULTIPLICAÇÃO

Sep 23rd, 2022
913
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React, { useState } from 'react'
  2. import {v4 as uuid} from 'uuid'
  3.  
  4. function App(){
  5.  
  6.     const [valor, setValor] = useState(1)
  7.    
  8.     const multiplicar = () => {
  9.         if(isNaN(valor))
  10.             return []
  11.  
  12.         let produtos = []
  13.  
  14.         for(let m = 1; m <= 10; m++)
  15.             produtos.push(valor * m)
  16.         return produtos
  17.     }
  18.  
  19.     return (
  20.         <>
  21.             <h1>React - Tabuada</h1>
  22.             <hr />
  23.             <input type="number" onChange={e => setValor(parseInt(e.target.value))} value={valor} />
  24.             { multiplicar().map((item, index) => <p key={uuid()}>{valor}x{index+1} = {item}</p>) }
  25.         </>
  26.     )
  27. }
  28.  
  29. export default App
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement