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

99
Views
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 answers
Answer question

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 Report
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!