Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

209
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!