goit-js-hw-05 was createdtask-номер_завдання.js Use <script type="module"> to close the task code in a separate scope and avoid conflicts of identifier names. Write an Account designer that creates an object with login and email properties. In prototype , the designer has given the getInfo() method, which outputs the login and email of the object that caused it to the console.
console . log ( Account . prototype . getInfo ) ; // function
const mango = new Account ( {
login : "Mangozedog" ,
email : "[email protected]" ,
} ) ;
mango . getInfo ( ) ; // Login: Mangozedog, Email: [email protected]
const poly = new Account ( {
login : "Poly" ,
email : "[email protected]" ,
} ) ;
poly . getInfo ( ) ; // Login: Poly, Email: [email protected] Write a User class to create a user with the following properties:
name - a lineage is a numberfollowers - number getInfo() was added, which, derives line: User ${ім'я} is ${вік} years old and has ${кількість фоловерів} followers
const mango = new User ( {
name : "Mango" ,
age : 2 ,
followers : 20 ,
} ) ;
mango . getInfo ( ) ; // User Mango is 2 years old and has 20 followers
const poly = new User ( {
name : "Poly" ,
age : 3 ,
followers : 17 ,
} ) ;
poly . getInfo ( ) ; // User Poly is 3 years old and has 17 followers Write the Storage Class that will create objects to manage the composition of goods. When the call, will receive one argument - the initial array of goods, and record it in the property of items .
Add Class Methods:
getItems() - returns an array of current goodsaddItem(item) - gets a new item and adds to currentremoveItem(item) - gets goods and, if any, deletes it from current const storage = new Storage ( [
"Нанітоіди" ,
"Пролонгер" ,
"Залізні жупи" ,
"Антигравітатор" ,
] ) ;
const items = storage . getItems ( ) ;
console . table ( items ) ; // [ "Нанітоіди", "Пролонгер", "Залізні жупи", "Антигравітатор" ]
storage . addItem ( "Дроїд" ) ;
console . table ( storage . items ) ; // [ "Нанітоіди", "Пролонгер", "Залізні жупи", "Антигравітатор", "Дроїд" ]
storage . removeItem ( "Пролонгер" ) ;
console . table ( storage . items ) ; // [ "Нанітоіди", "Залізні жупи", "Антигравітатор", "Дроїд" ] Write the StringBuilder class. It receives one parameter on the input - a line that writes into the property _value .
Add the class following functionality:
value - Returns Current Field _valueappend(str) method - gets str (string) and adds to the end _valueprepend(str) method - gets str (string) and adds to the beginning _valuepad(str) method - gets Str (string) and adds to the beginning and at the end _value const builder = new StringBuilder ( "." ) ;
builder . append ( "^" ) ;
console . log ( builder . value ) ; // '.^'
builder . prepend ( "^" ) ;
console . log ( builder . value ) ; // '^.^'
builder . pad ( "=" ) ;
console . log ( builder . value ) ; // '=^.^=' Write a Car class with these properties and methods.
class Car {
/*
* Додай статичний метод `getSpecs(car)`,
* який приймає об'єкт-машину як параметр і виводить
* в консоль значення властивостей maxSpeed, speed, isOn, distance и price.
*/
/*
* Конструктор отримує об'єкт налаштувань.
*
* Додай властивості майбутнього екземпляра класу:
* speed - поточна швидкість, початкова 0
* price - ціна автомобіля
* maxSpeed - максимальна швидкість
* isOn - заведений автомобіль, значення true або false. Спочатку false
* distance - загальний кілометраж, спочатку 0
*/
constructor ( ) { }
/*
* Додай геттер і сеттер для властивості price,
* який буде працювати з властивістю ціни автомобіля.
*/
/*
* Додай код для того, щоб завести автомобіль
* Записує у властивість isOn значення true
*/
turnOn ( ) { }
/*
* Додай код для того, щоб заглушити автомобіль
* Записує у властивість isOn значення false,
* і скидає поточну швидкість в 0
*/
turnOff ( ) { }
/*
* Додає до властивості speed отримане значення,
* за умови, що результуюча швидкість
* не більше, ніж значення властивості maxSpeed
*/
accelerate ( value ) { }
/*
* Забирає від властивості speed отримане значення,
* за умови, що результуюча швидкість не менше нуля
*/
decelerate ( value ) { }
/*
* Додає в поле distance кілометраж (hours * speed),
* але тільки в тому випадку, якщо машина заведена!
*/
drive ( hours ) { }
}
const mustang = new Car ( { maxSpeed : 200 , price : 2000 } ) ;
mustang . turnOn ( ) ;
mustang . accelerate ( 50 ) ;
mustang . drive ( 2 ) ;
Car . getSpecs ( mustang ) ;
// maxSpeed: 200, speed: 50, isOn: true, distance: 100, price: 2000
mustang . decelerate ( 20 ) ;
mustang . drive ( 1 ) ;
mustang . turnOff ( ) ;
Car . getSpecs ( mustang ) ;
// maxSpeed: 200, speed: 0, isOn: false, distance: 130, price: 2000
console . log ( mustang . price ) ; // 2000
mustang . price = 4000 ;
console . log ( mustang . price ) ; // 4000