-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlesson2.js
More file actions
126 lines (103 loc) · 2.01 KB
/
lesson2.js
File metadata and controls
126 lines (103 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
'use strict';
//chapter2 качество кода ----------------
//----------- objects --------------
/*
let user = {
name: 'nn',
surname: 'smith',
};
user.name='pit';
delete user.surname;
alert(user.name+user.surname);
*/
//-----------------
/*
function isEmpty(obj) {
for (let key in obj) {
if (key in obj) return false;
}
return true;
}
let user = {};
alert(isEmpty(user));
user.name='john';
alert(isEmpty(user));*/
//--------------------------
/*
let salaries = {
John: 100,
Ann: 160,
Pete: 130
};
let sum=0;
for (let key in salaries){
sum+=salaries[key];
alert(sum);
}
alert(sum);*/
//-----------------
/*
let menu = {
width: 200,
height: 300,
title: "My menu"
};
function multiplyNumeric(obj) {
for (let key in obj) {
if (typeof obj[key] === 'number') obj[key] += obj[key];
}
}
multiplyNumeric(menu);
for (let key in menu) {
alert(key+' : '+menu[key]);
}
*/
//--------------------------calculator
/*
let calculator = {
read() {
this.a = prompt('a?');
this.b = prompt('b?');
},
sum() {
return ((+this.a) + (+this.b));
},
mul() {
return (this.a * this.b)
},
};
calculator.read();
alert(calculator.sum());
alert(calculator.mul());
*/
//---------------------calc
/*
function Calculator()
{
this.read = function () {
this.a = prompt('a?');
this.b = prompt('b?');
};
this.sum=function () {
return ((+this.a)+(+this.b));
};
this.mul=function () {
return (this.a*this.b)
};
}
let calculator = new Calculator();
calculator.read();
alert("Sum=" + calculator.sum());
alert("Mul=" + calculator.mul());
*/
//------------------------------------ constructor
/*function Accumulator(startingValue) {
this.value = startingValue;
this.read = function (readValue) {
this.value += +prompt('value?', '50')+readValue;
};
}
let accumulator=new Accumulator(100);
accumulator.read(5);
accumulator.read(5);
alert(accumulator.value);*/