Looping_code confusing

const people = [‘Chris’, ‘Anne’, ‘Colin’, ‘Terri’, ‘Phil’, ‘Lola’, ‘Sam’, ‘Kay’, ‘Bruce’];

const admitted = document.querySelector(’.admitted’);
const refused = document.querySelector(’.refused’);

admitted.textContent = 'Admit: ';
refused.textContent = 'Refuse: ’
let i = 0;

do {
if(people[i] === ‘Phil’ || people[i] === ‘Lola’) {
refused.textContent += people[i] + ', ';
} else {
admitted.textContent += people[i] + ', ';
}
i++;
} while(i < people.length);

refused.textContent = refused.textContent.slice(0,refused.textContent.length-2) + ‘.’;
admitted.textContent = admitted.textContent.slice(0,admitted.textContent.length-2) + ‘.’;

//I can’ t understand last two code line, why -2 ? Can you explain it, thank you!

Hi @hahawill!

In each iteration of the loop we are adding a comma and a space on to the end of the refused or admitted paragraph. But we don’t want this on the very end of the paragraphs. So these last two lines slice off the last two characters of each paragraph (hence -2), and then add a full stop back on, to make for proper sentence structure.