goit-js-hw-03 repository was createdtask-номер_завдання.js Use <script type="module"> to close the task code in a separate scope and avoid conflicts of identifier names. Write a script that, for a user object, sequentially:
mood field with value 'happy'hobby value by 'skydiving'premium value on falseuser in ключ:значення using Object.keys() and for...of const user = {
name : "Mango" ,
age : 20 ,
hobby : "html" ,
premium : true ,
} ; Write countProps(obj) feature that counts the number of properties in the object. The function returns the number - the number of properties.
const countProps = function ( obj ) {
// твій код
} ;
/*
* Викличи функції для перевірки працездатності твоєї реалізації.
*/
console . log ( countProps ( { } ) ) ; // 0
console . log ( countProps ( { name : "Mango" , age : 2 } ) ) ; // 2
console . log ( countProps ( { mail : "[email protected]" , isOnline : true , score : 500 } ) ) ; // 3 Write the findBestEmployee(employees) feature that accepts the object of employees and returns the name of the most productive (which performed more of all tasks). Employees and the number of tasks completed are contained as the properties of the object in the format "ім'я":"кількість задач" .
const findBestEmployee = function ( employees ) {
// твій код
} ;
/*
* Викличи функції для перевірки працездатності твоєї реалізації.
*/
console . log (
findBestEmployee ( {
ann : 29 ,
david : 35 ,
helen : 1 ,
lorence : 99 ,
} )
) ; // lorence
console . log (
findBestEmployee ( {
poly : 12 ,
mango : 17 ,
ajax : 4 ,
} )
) ; // mango
console . log (
findBestEmployee ( {
lux : 147 ,
david : 21 ,
kiwi : 19 ,
chelsy : 38 ,
} )
) ; // lux Write the countTotalSalary(employees) File Scale Object. The function calculates the total amount of employees' salaries and returns it. Each field of the object transmitted to the function has the form of "ім'я":"зарплата" .
const countTotalSalary = function ( employees ) {
// твій код
} ;
/*
* Викличи функції для перевірки працездатності твоєї реалізації.
*/
console . log ( countTotalSalary ( { } ) ) ; // 0
console . log (
countTotalSalary ( {
mango : 100 ,
poly : 150 ,
alfred : 80 ,
} )
) ; // 330
console . log (
countTotalSalary ( {
kiwi : 200 ,
lux : 50 ,
chelsy : 150 ,
} )
) ; // 400 Write getAllPropValues(arr, prop) feature that receives an array of objects and property name. Returns an array of values of a certain prop property from each object in an array.
const products = [
{ name : "Радар" , price : 1300 , quantity : 4 } ,
{ name : "Сканер" , price : 2700 , quantity : 3 } ,
{ name : "Дроїд" , price : 400 , quantity : 7 } ,
{ name : "Захоплення" , price : 1200 , quantity : 2 } ,
] ;
const getAllPropValues = function ( arr , prop ) {
// твій код
} ;
/*
* Викличи функції для перевірки працездатності твоєї реалізації.
*/
console . log ( getAllPropValues ( products , "name" ) ) ; // ['Радар', 'Сканер', 'Дроїд', 'Захоплення']
console . log ( getAllPropValues ( products , "quantity" ) ) ; // [4, 3, 7, 2]
console . log ( getAllPropValues ( products , "category" ) ) ; // [] Write the calculateTotalPrice(allProdcuts, productName) function that receives an object array and product name ( name property value). Returns the total cost of the product (price * quantity).
Call functions to check your implementation.
const products = [
{ name : "Радар" , price : 1300 , quantity : 4 } ,
{ name : "Сканер" , price : 2700 , quantity : 3 } ,
{ name : "Дроїд" , price : 400 , quantity : 7 } ,
{ name : "Захоплення" , price : 1200 , quantity : 2 } ,
] ;
const calculateTotalPrice = function ( allProdcuts , productName ) {
// твій код
} ;
/*
* Викличи функції для перевірки працездатності твоєї реалізації.
*/
console . log ( calculateTotalPrice ( products , "Радар" ) ) ; // 5200
console . log ( calculateTotalPrice ( products , "Дроїд" ) ) ; // 2800 Write a scenario of managing the personal office of the Internet bank. There is an account of accounting in which it is necessary to implement methods to work with the balance sheet and the history of transactions.
/*
* Типів транзацкій всього два.
* Можна покласти або зняти гроші з рахунку.
*/
const Transaction = {
DEPOSIT : "deposit" ,
WITHDRAW : "withdraw" ,
} ;
/*
* Кожна транзакція - це об'єкт з властивостями: id, type і amount
*/
const account = {
// Поточний баланс рахунку
balance : 0 ,
// Історія транзакцій
transactions : [ ] ,
/*
* Метод створює і повертає об'єкт транзакції.
* Приймає суму і тип транзакції.
*/
createTransaction ( amount , type ) { } ,
/*
* Метод відповідає за додавання суми до балансу.
* Приймає суму танзакції.
* Викликає createTransaction для створення об'єкта транзакції
* після чого додає його в історію транзакцій
*/
deposit ( amount ) { } ,
/*
* Метод відповідає за зняття суми з балансу.
* Приймає суму танзакції.
* Викликає createTransaction для створення об'єкта транзакції
* після чого додає його в історію транзакцій.
*
* Якщо amount більше, ніж поточний баланс, виводь повідомлення
* про те, що зняття такої суми не можливо, недостатньо коштів.
*/
withdraw ( amount ) { } ,
/*
* Метод повертає поточний баланс
*/
getBalance ( ) { } ,
/*
* Метод шукає і повертає об'єкт транзакції по id
*/
getTransactionDetails ( id ) { } ,
/*
* Метод повертає кількість коштів
* певного типу транзакції з усієї історії транзакцій
*/
getTransactionTotal ( type ) { } ,
} ;