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

179
Vistas
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
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