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

104
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
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