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

97
Visualizações
Using different array's with switch statements

I am creating a recycling app and am attempting to use a switch statement to provide the user with instructions on what to do with the item upon entering into an input field. I'm a little turned around on how to call it (I am very new to switch). Eventually I want to have a few different arrays according to material. How would I place the item's within an array in the a switch? Would I be better off with if else statements? Any advice would be much appreciated!

const plasticItem = ["Milk Jug , Shampoo, Deodarant, Soda Bottle"];

function recycleItem(plasticItem) {
    let instructions = "";

    switch (true) {
        case plasticItem: 
        instructions = "Put in recycling"; 
        break;
    }
}

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I made this code which should work:

function recycleItem(){
        const x = document.querySelector("input").value;
        switch(x) {
          case "Milk Jug":
            console.log("Milk");
            break;
          case "Shampoo":
            // code block
            console.log("Shampoo");
            break;
          case "Deodarant":
            console.log("Deodarant");
            break
          case "Soda Bottle":
            console.log("Soda Bottle");
            break
          default:
            // code block
        } 
    }
about 4 years ago · Juan Pablo Isaza Relatório
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