Answer the question
In order to leave comments, you need to log in
How to do simple validation in JS?
There is a simple code - the user enters the first and last name separated by a space until he clicks Cancel, after which the data array is output to the console.
function User(firstName, lastName){
this.firstName = firstName;
this.lastName = lastName;
this.regDate = new Date();
}
function UserList(){
this.users = [];
this.add = function(user) {
this.users.push(user);
}
this.getAllUsers = function(){
return this.users;
}
}
var userList = new UserList();
while (true) {
var i = prompt('Введите имя и фамилию через пробел!');
if(!i) break;
i = i.split(' ');
var user = new User(i[0], i[1]);
userList.add(user);
}
console.log(userList.getAllUsers());
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question