Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions HomeWork/js/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
'use strict';

function Calculator() {
this.firstValue = 0;
this.secondValue = 0;

this.read = function() {
this.firstValue = parseFloat(prompt('Введіть перше число:', 0));
this.secondValue = parseFloat(prompt('Введіть друге число:', 0));
}

this.sum = function() {
return this.firstValue + this.secondValue;
};

this.mul = function() {
return this.firstValue * this.secondValue;
};
}

let calculator = new Calculator();

calculator.read();

console.log('Сума:' + calculator.sum());
console.log('Добуток:' + calculator.mul());
4 changes: 2 additions & 2 deletions Lesson/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
<title>Lesson 7</title>
</head>
<body>
<!-- <div id="circleRed"></div>
<div id="circleRed"></div>
<div id="circleGreen"></div>
<div id="circleBlack"></div> -->
<div id="circleBlack"></div>

<script src="./js/script.js" ></script>
</body>
Expand Down
184 changes: 107 additions & 77 deletions Lesson/js/script.js
Original file line number Diff line number Diff line change
@@ -1,77 +1,107 @@
// class CircleBox {
// constructor(selector) {
// this.$el = document.querySelector(selector);
// }

// hide() {
// this.$el.style.display = "none";
// }

// show() {
// this.$el.style.display = "block";
// }
// }

// class CircleItem extends CircleBox {
// constructor(options) {
// super(options.selector);
// this.$el.style.width = options.size + "px";
// this.$el.style.height = options.size + "px";
// this.$el.style.borderRadius = "50%";
// this.$el.style.background = options.color;
// }
// }

// const CircleRed = new CircleItem({
// selector: "#circleRed",
// color: "red",
// size: 50,
// });

// const CircleGreen = new CircleItem({
// selector: "#circleGreen",
// color: "green",
// size: 80,
// });

// const CircleBlack = new CircleItem({
// selector: "#circleBlack",
// color: "black",
// size: 30,
// });

// function Car(name, color) {
// this.name = name;
// this.color = color;
// }

// Car.prototype.message = function () {
// console.log(`${this.name} is ${this.color} color`);
// };

// Car.prototype.start = function () {
// console.log(`${this.name} is start!!!`);
// };

// const BMW = new Car("bmw", "red");
// const opel = new Car("opel", "green");

// let message = {
// messageHello() {
// console.log(`Hello, ${this.name}`);
// },

// messageBey() {
// console.log(`Bye, ${this.name}`);
// },
// };

// class User {
// constructor(name) {
// this.name = name;
// }
// }

// Object.assign(User.prototype, message);

// new User("Іван").messageHello();
class CircleBox {
constructor(selector) {
this.$el = document.querySelector(selector);
}

hide() {
this.$el.style.display = "none";
}

show() {
this.$el.style.display = "block";
}
}

class CircleItem extends CircleBox {
constructor(options) {
super(options.selector);
this.$el.style.width = options.size + "px";
this.$el.style.height = options.size + "px";
this.$el.style.borderRadius = "50%";
this.$el.style.background = options.color;
}
}

const CircleRed = new CircleItem({
selector: "#circleRed",
color: "red",
size: 50,
});

const CircleGreen = new CircleItem({
selector: "#circleGreen",
color: "green",
size: 80,
});

const CircleBlack = new CircleItem({
selector: "#circleBlack",
color: "black",
size: 30,
});



///---------------

function Car(name, color) {
this.name = name;
this.color = color;
}

Car.prototype.message = function () {
console.log(`${this.name} is ${this.color} color`);
};

Car.prototype.start = function () {
console.log(`${this.name} is start!!!`);
};

const BMW = new Car("bmw", "red");
const opel = new Car("opel", "green");


// Mixin
///--------------
let message = {
messageHello() {
console.log(`Hello, ${this.name}`);
},

messageBey() {
console.log(`Bye, ${this.name}`);
},
};

class User {
constructor(name) {
this.name = name;
}
}

Object.assign(User.prototype, message);

new User("Іван").messageHello();

if (!Math.trunc){};//якщо новий метод не працює, пишемо його логіку самостійно

// додавати опис компонентів високого рівня, що вони роблять та як взаємодіють

// коментувати
// -- загальну архітектуру високого рівня
// -- використання функцій
// -- важливі рішення якщо вони не очевидні

// писати читабельний та максимально зрозумілий простий код

function createEleme() {}

function useElem() {}

function useElemItem(){}

let elem = createElem(); // оголошуємо або спочатку або вкінці
useElem();
useElemItem();

// використовувати зрозумілі імена змінних та функцій