-1

function tabuada() {
    let num = document.getElementById('txtn')
    let tab = document.getElementById('seltab')
    if (num.value.length == 0) {
        window.alert('Por favor,digite um número!')
    } else {
        let n = Number(num.value)
        let c = 1;
        tab.innerHTML = ''
        while (c <= 10) {
            let item = document.createElement('option')
            item.text =`${n} x ${c} = ${num*c}`
            tab.appendChild(item)
            c++
        }
    }
}
body{
    background: rgb(151, 158, 46);
    font: normal 15pt Arial;
}
header{
    color:white;
    text-align: center;
}
section{
    background: white;
    border-radius:10px;
    padding: 15px;
    width: 500px;
    margin: auto;
    box-shadow: 5px 5px 10px rgb(233, 230, 72);

}
footer{
    color:white;
    text-align: center;
    font-style: italic;
}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Tabuada online em js</title>
    <link rel="stylesheet" href="estiloTabuada.css"><!--presionar ctrl e clicar para gerar a sugestão de criar um arquivo css-->
    
</head>
<body>
    <header>
        <h1>Tabuada!</h1>
    </header>
    <section>
        <div>
            <p>Número: <input type="number" name="num" id="txtn"> 
            <input type ="button" value="Gerar Tabuada" onclick="tabuada()">
            </p>
        </div>
        <div>
            <select name="Tabuada" id="seltab"></select>
            <option>Digite um número acima</option>
        </div>
        	
    </section>
    <footer>
        <p>&copy;Yvan.</p>
    </footer>
    <script src="scriptTabuada.js"></script>
    
</body>
</html>

1
  • E qual seria sua dúvida? 6/09/2019 às 17:39

2 Respostas 2

1

Esta linha está incorreta brother:

item.text =`${n} x ${c} = ${num*c}`

Altere para:

item.text =`${n} x ${c} = ${n*c}`
1
  • 1
    obrigado amigão. tmj 6/09/2019 às 16:16
0

Algoritmo abaixo:

function multiplicar(multiplicando,multiplicador){
  const resultado = []
  return function(multiplicador){
    while(multiplicador >= 0){
      resultado.push(multiplicando * multiplicador)
      multiplicador = multiplicador-1
    }
    return resultado.reverse()
  }

}
console.log( multiplicar(3)(10) )

Esta não é a resposta que você está procurando? Pesquise outras perguntas com a tag .