Skip to content

Commit ca4bd89

Browse files
Balashov NikitaOlegLustenko
authored andcommitted
chenge add and methods names
1 parent 6ce2158 commit ca4bd89

File tree

1 file changed

+13
-20
lines changed
  • js-core/homeworks/phoneApp/src

1 file changed

+13
-20
lines changed

js-core/homeworks/phoneApp/src/main.js

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
//function User() {
2-
// return {};
3-
//}
1+
function User(addArgument) {
2+
this.name = addArgument.name;
3+
this.surname = addArgument.surname;
4+
this.number = addArgument.number;
5+
this.city = addArgument.city;
6+
this.company = addArgument.company;
7+
}
48

59
function PhoneApp() {
610
this.storage = [];
@@ -21,8 +25,8 @@ PhoneApp.prototype.isNumber = function(stringToCheck) {
2125
return flag !== false;
2226
}
2327

24-
PhoneApp.prototype.formatedPhoneNumber = function(numberToSort) {
25-
const toStringTheNumber = numberToSort.toString();
28+
PhoneApp.prototype.createFormatedPhoneNumber = function(phoneNumber) {
29+
const toStringTheNumber = phoneNumber.toString();
2630
const toArrayTheString = toStringTheNumber.split('');
2731
let rewritedArray = [];
2832

@@ -57,22 +61,11 @@ PhoneApp.prototype.formatedPhoneNumber = function(numberToSort) {
5761
}
5862
}
5963

60-
//PhoneApp.prototype.add = function(name, number, surname = null, city = null, company = null) {
61-
// const idNumber = this.storage.length + 1;
62-
// const contact = new User();
63-
// contact.id = idNumber;
64-
// contact.name = name;
65-
// contact.surname = surname;
66-
// contact.number = this.formatedPhoneNumber(number);
67-
// contact.city = city;
68-
// contact.company = company;
69-
// this.storage.push(contact);
70-
//}
7164
PhoneApp.prototype.add = function(object) {
7265
const idNumber = this.storage.length + 1;
73-
const contact = object;
66+
const contact = new User(object);
7467
contact.id = idNumber;
75-
contact.number = this.formatedPhoneNumber(contact.number)
68+
contact.number = this.createFormatedPhoneNumber(contact.number)
7669
this.storage.push(contact);
7770
}
7871

@@ -116,9 +109,9 @@ PhoneApp.prototype.changeValueByIndex = function(index, key, value) {
116109
const test = new PhoneApp();
117110

118111
test.add({name: 'Nikita', number: '1234567890', surname: 'Balashov', city: 'Kharkiv', company: null});
119-
test.add({name: 'Nikita', number: '0987655321', surname: 'Smith', city: null, comapny: null});
112+
test.add({name: 'Nikita', number: '0987655321', surname: 'Smith', city: null, company: null});
120113
test.add({name: 'Paul', number: '0893127823', surname: 'Smith', city: 'Kharkiv', company: null});
121-
test.add({name: 'Paul', number: '0897612374', surname: 'Balashov', city: null, comapny: null});
114+
test.add({name: 'Paul', number: '0897612374', surname: 'Balashov', city: null, company: null});
122115

123116
console.log(test.storage);
124117
console.log(test.filterByValue('name', 'Nikita'));

0 commit comments

Comments
 (0)