Instruct ur Notes Help O IDE Settings Challenge: Should we order this candy? We want to know whether to order a particular candy. We should make an order if the total number in stock ( instock ) is less than the weekly average sold ( weeklyAverage ). Create a function called shouldweOrderThisCandy that takes in: • the inventory array • aspecific type of candy (string) The function should find the candy in the array that matches the name passed in. When that candy is found, return true if the number inStock is less than the weeklyAverage. Otherwise, return false. If the array doesn't have any candy with that name, return false Example input and output shouldweOrderThisCandy(inventory, "Twizzlers"); //-> true shouldweOrder ThisCandy (inventory, "Sour Patch Kids"); //-> true shouldweOrderThisCandy(inventory, "Milk Duds"); //-> false shouldweOrderThisCandy(inventory, "Now and Laters"); //-> false shouldweOrderThisCandy(inventory, "Broccoli Bits"); //-> false Sample inventory array This is a sample of the data that will be used in all of the challenges. let inventory = [ { candy: "Twizzlers", inStock: 180, weeklyAverage: 200 }, ( candy: "Sour Patch Kids", instock: 90, weeklyAverage: 100 }, { candy: "Milk Duds", instock: 300, weeklyAverage: 170 }. ( candy: "Now and Laters", instock: 15e, weeklyAverage: 40 ) Time: 769ms Passed: 0 Failed: 7 Exit Code: 7 Test Results:

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
this is JavaScript programming. please provide step by step code.
RUN TESTS
SUBMIT SOLUTION
NEXT CHALLENGE
Instruct
ur Notes
O Help
* IDE Settings
Challenge: Should we order this candy?
We want to know whether to order a particular candy. We should make an order if the total number
in stock ( instock ) is less than the weekly average sold ( weeklyAverage ).
Create a function called shouldWeOrderThisCandy that takes in:
• the inventory array
• a specific type of candy (string)
The function should find the candy in the array that matches the name passed in.
When that candy is found, return true if the number inStock is less than the weeklyAverage.
Otherwise, return false.
If the array doesn't have any candy with that name, return false.
Example input and output
shouldweorderThisCandy (inventory, "Twizzlers"); //-> true
shouldweOrderThisCandy (inventory, "Sour Patch Kids"); //-> true
shouldweOrderThisCandy (inventory, "Milk Duds"); //-> false
shouldWeOrderThisCandy (inventory, "Now and Laters"); //-> false
shouldweOrderThisCandy (inventory, "Broccoli Bits"); //-> false
Help
Sample inventory array
This is a sample of the data that will be used in all of the challenges.
let inventory = [
{ candy: "Twizzlers", inStock: 180, weeklyAverage: 200 },
{ candy: "Sour Patch Kids", instock: 90, weeklyAverage: 100 },
{ candy: "Milk Duds", instock: 300, weeklyAverage: 170 ),
( candy: "Now and Laters", instock: 150, weeklyAverage: 40 }
Time: 769ms Passed: 0 Failed: 7 Exit Code: 7
I Test Results:
9:23 PM
2/22/2022
ENG
Transcribed Image Text:RUN TESTS SUBMIT SOLUTION NEXT CHALLENGE Instruct ur Notes O Help * IDE Settings Challenge: Should we order this candy? We want to know whether to order a particular candy. We should make an order if the total number in stock ( instock ) is less than the weekly average sold ( weeklyAverage ). Create a function called shouldWeOrderThisCandy that takes in: • the inventory array • a specific type of candy (string) The function should find the candy in the array that matches the name passed in. When that candy is found, return true if the number inStock is less than the weeklyAverage. Otherwise, return false. If the array doesn't have any candy with that name, return false. Example input and output shouldweorderThisCandy (inventory, "Twizzlers"); //-> true shouldweOrderThisCandy (inventory, "Sour Patch Kids"); //-> true shouldweOrderThisCandy (inventory, "Milk Duds"); //-> false shouldWeOrderThisCandy (inventory, "Now and Laters"); //-> false shouldweOrderThisCandy (inventory, "Broccoli Bits"); //-> false Help Sample inventory array This is a sample of the data that will be used in all of the challenges. let inventory = [ { candy: "Twizzlers", inStock: 180, weeklyAverage: 200 }, { candy: "Sour Patch Kids", instock: 90, weeklyAverage: 100 }, { candy: "Milk Duds", instock: 300, weeklyAverage: 170 ), ( candy: "Now and Laters", instock: 150, weeklyAverage: 40 } Time: 769ms Passed: 0 Failed: 7 Exit Code: 7 I Test Results: 9:23 PM 2/22/2022 ENG
Expert Solution
Step 1

We need to to provide Javascript code for given scenario

Algorithm:


1. Defined function shouldWeOrderThisCandy(..) with pass inventory and candy type as argument
2.  find if the input candy is in the inventory array loop though inventory
3. return true if inStock is less than the weekly average sold (weeklyAverage)
4. if not return false.
5. return false indicate that candy type is not in the inventory array.

trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY