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:
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...
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](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fcec9af66-e90b-4158-916c-0cabece102ed%2Ff5bf279f-dfc0-478a-83b9-720fb5784d3e%2Fzxqvt0l_processed.jpeg&w=3840&q=75)
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
![](/static/compass_v2/shared-icons/check-mark.png)
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
This is a popular solution!
Step by step
Solved in 3 steps with 1 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
Recommended textbooks for you
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
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…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
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)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
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…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
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)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
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](https://www.bartleby.com/isbn_cover_images/9781337093422/9781337093422_smallCoverImage.gif)
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
![Prelude to Programming](https://www.bartleby.com/isbn_cover_images/9780133750423/9780133750423_smallCoverImage.jpg)
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
![Sc Business Data Communications and Networking, T…](https://www.bartleby.com/isbn_cover_images/9781119368830/9781119368830_smallCoverImage.gif)
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY