var prompt = "Welcome,",
prompt2 = "How are you?",
prompt3 = "Good to see you again.",
counter = 0,
users = [];
var greeting = function(user){
var greeting = prompt + " ";
// if this is a new user, say hello
if (newUser(user)) {
greeting += prompt2;
} else {
// if we've met before, welcome them back
greeting += prompt3;
}
console.log(greeting);
counter++;
};
var newUser = function(user) {
// have we encountered this user before?
for (let i = 0; i < users.length; i++) {
if (users[i].toUpperCase() === user.toUpperCase()) {
return false;
}
}
// if not, register the user
addUser(user);
return true;
};
var addUser = function(user) {
users.push(user);
};
var numberOfGreetings = function() {
console.log("Total number of greetings: " + counter);
};