Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

207
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda