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

176
Views
My switch keeps terminating after 1st,I am trying to create a button that calls different functions as I click it using JavaScript switch statements

I tried this using if statements and it worked but i can figure out why this switch keeps terminating after the first case is through.

 const buttonOne =  document.getElementById('buttonOne');

 buttonOne.addEventListener('click', function() {
   const row = document.querySelectorAll('.row');
   const imgOne = document.querySelector('.rowOne');
   const imgTwo = document.querySelector('.rowTwo');
   const imgThree = document.querySelector('.rowThree');
   const imgFour = document.querySelector('.rowFour');
   const imgFive = document.querySelector('.rowFive');
   const imgSix = document.querySelector('.rowSix');

let counter = 0;

    switch (++counter) {
        case 1:     imgOne.innerHTML = '<img src="images/image01.jpg">';

            
            break;
        case 2:     imgTwo.innerHTML = '<img src="images/image02.jpg">';

            
            break;
        case 3:    imgThree.innerHTML = '<img src="images/image03.jpg">';

            
            break;
        case 4:    imgFour.innerHTML = '<img src="images/image04.jpg">';

            
            break;
        case 5:     imgFive.innerHTML = '<img src="images/image05.jpg">';

            
            break;
        case 6:     imgSix.innerHTML = '<img src="images/image06.jpg">';

            
            break
    
        default: row.innerHTML = '<img src="images/logo.png">';
        
    }
    counter = 0;
   })

I tried this using if statements and it worked but i can figure out why this switch keeps terminating after the first case is through.

about 4 years ago · Juan Pablo Isaza
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!