Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

210
Visualizações
Trying to get the HTML displayed to change every time a new button is clicked with jquery
let table = 6;
let i = 1;
$(function() {
    let $newOperatorButton = $('button');
       
    $newOperatorButton.on('click', function math(){
            let msgOperator = '';
            let expression;
            let operator = $(this).attr("value");
            if(operator === '+'){
                msgOperator = ' + ';
                expression = (table + i);
                while(i < 11){
                    msg += table + msgOperator + i + ' = ' + (table + i) + '<br />';
                    i++; 
                }
            } else if (operator === '-') {
                msgOperator = ' - ';
                expression = (table - i);
                while(i < 11){
                    msg += table + msgOperator + i + ' = ' + (table - i) + '<br />';
                    i++; 
                }

some code missing but it adds multiplication and division

            let el = document.getElementById('blackboard');
            el.innerHTML = msg;
        
        }
    );
});

This code is inside the body tag in my index.html

        <section id="page">
            <section id="blackboard"></section>
        </section>
        <form id="operator">
            <button name="add" type="button" value="+">+</button>
            <button name="subtract" type="button" value="-">-</button>
            <button name="multiply" type="button" value="x">x</button>
            <button name="division" type="button" value="/">/</button>
        </form>

        <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
        <script src="/index.js"></script>

I have it so it prints out a table with 10 numbers depending on the button clicked. For ex. table = 6 and i = 1 is 6+1=7.... 6+10=16

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You need an if statement at the end that reset your equations and variables.

after you've run your equation "i" is still equal to 11 so it never passes into the while loops again, you also need to empty your message so it doesn't keep adding addition text to your existing text.

 $("#blackboard").html(msg)
         
        if (i == 11) {
            
            i = 1
            msg = ""
            
        }
     
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda