let field = document.querySelector('#field');
let message = document.querySelector('#message');
var cities = [];
field.addEventListener('blur', function () {
if (doChecks(field.value)) {
cities.push(field.value);
console.log(cities);
} else {
console.log('Checks failed');
}
});
function doChecks(val) {
if (cities.includes(val)) {
return false;
}
if (cities.length > 0) {
const last = cities[cities.length - 1];
if (last[last.length - 1] !== val[0]) {
return false;
}
}
return true;
}