Answer to Question #269977 in HTML/JavaScript Web Application for prime

Question #269977

I want to pass all test cases

Sample Output 1

Item Found

Sample Output 2

Category Not Found

let inputString = "";

let currentLine = 0;

process.stdin.on("data", (inputStdin) => {

 inputString += inputStdin;

});

process.stdin.on("end", (_) => {

 inputString = inputString.trim().split("\n").map((str) => str.trim());

 main();

});

function readLine() {

 return inputString[currentLine++];

}

function main() {

 const categoryOfItem = readLine();

 const item = readLine();

 const mart = [

  {

   category:"pulses",

   items: ["green gram", "green peas", "Turkish gram"]

  },

  {

   category:"soaps",

   items:["santoor", "dove", "lux", "pears"]

  },

 ]; 

 /* Write your code here */

}



1
Expert's answer
2021-11-25T07:53:43-0500
let inputString = "";
let currentLine = 0;
process.stdin.on("data", (inputStdin) => {
 inputString += inputStdin;
});
process.stdin.on("end", (_) => {
 inputString = inputString.trim().split("\n").map((str) => str.trim());
 main();
});
function readLine() {
 return inputString[currentLine++];
}
function main() {
 const categoryOfItem = readLine();
 const item = readLine();
 const mart = [
  {
   category:"pulses",
   items: ["green gram", "green peas", "Turkish gram"]
  },
  {
   category:"soaps",
   items:["santoor", "dove", "lux", "pears"]
  },
 ]; 
 let found = false;
 for (int i = 0; i < mart.length; i++) {
   if (item === mart.category)
     found = true;
 }
 if (found)
  console.log("Item Found")
 else 
  console.log("Category Not Found")
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS