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

177
Visualizações
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 à 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