← All tools

VuToV-Mykola/goit-js-hw-04

Popularity 60 Updated Development & Build

📌 GoIT Homework-JS #4: JavaScript fundamentals - objects, methods, and array operations. Three tasks: product capacity checking, average calorie calculation, and player profile management.

githubauto-collected

Installation

A directly usable install command is not verified yet. Check the project documentation or releases.

📸 Скріншот проекту

<!-- END:AUTOGEN --

My Achievements

My Certificates - Completed Sololearn Course:

SOLOLEARN

JavaScript Homework 04

Task 1. Product Packaging

COMPLETE THIS TASK IN THE FILE task-1.js

Write a function isEnoughCapacity(products, containerSize) that calculates whether all products will fit in the container during packaging.

The function declares two parameters:

  • products — an object where keys contain product names and their values are the quantity of these products. For example, { apples: 2, grapes: 4 }.
  • containerSize — a number, the maximum number of product units that the container can hold.

The function should return the result of checking whether all products will fit in the container. That is, calculate the total quantity of products in the products object and return true if it is less than or equal to containerSize, and false otherwise.

Take the code below and insert it after declaring your function to check the correctness of its work. The console will display the results of its calls.

console.log(
  isEnoughCapacity({ apples: 2, grapes: 3, carrots: 1 }, 8)
); // true

console.log(
  isEnoughCapacity({ apples: 4, grapes: 6, lime: 16 }, 12)
); // false

console.log(
  isEnoughCapacity({ apples: 1, lime: 5, tomatoes: 3 }, 14)
); // true

isEnoughCapacity({ apples: 18, potatoes: 5, oranges: 2 }, 7) ); // false


Leave this code for mentor verification.

### Mentor Review Criteria

- Declared function `isEnoughCapacity(products, containerSize)`
- Calling `isEnoughCapacity({ apples: 2, grapes: 3, carrots: 1 }, 8)` returns `true`
- Calling `isEnoughCapacity({ apples: 4, grapes: 6, lime: 16 }, 12)` returns `false`
- Calling `isEnoughCapacity({ apples: 1, lime: 5, tomatoes: 3 }, 14)` returns `true`
- Calling `isEnoughCapacity({ apples: 18, potatoes: 5, oranges: 2 }, 7)` returns `false`

## Task 2. Calorie Calculation

COMPLETE THIS TASK IN THE FILE task-2.js

Write a function calcAverageCalories(days) that returns the average daily value of the number of calories that an athlete consumed during the week. The function expects one parameter: days — an array of objects. Each object describes a day of the week and the number of calories consumed by the athlete on that day.