Active Learning: filling in a guest list - for loop solution not working?


I don’t understand why my code isn’t working - I used a for loop instead of a while loop. (this is without the bonus ‘part’):.

I have tried placing
admitted.textContent = “Admit”:;
refused.textContent = “Refuse”:

just before the for loop and also just before the closing } of the for loop, but neither of those solutions make any difference. What am I missing?*/

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

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

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

for (let i = 0; i < people.length; i++) {

admitted.textContent = 'Admit: ';

refused.textContent = 'Refuse: ‘;

if ((people[i] === “Lola”) || (people[] === “Phil”) ) {

refused.textContent += people[i] + ", ";


else {

admitted.textContent += people[i] + ", ";



/*All my best,

Sarah */

Hi there @Wonderbird_Pointyshoes, and welcome to our community! I’m more than happy to help you debug this.

So I think the main thing that was stopping your code from working was this bit — people[] === “Phil”— you forgot the i variable, and bracket notation won’t work without an index value specified.

Also, in its current form the code won’t work because you need to move the following outside the for loop:

admitted.textContent = 'Admit: ';

refused.textContent = 'Refuse: ‘;

If you have them inside the for loop, then each time the loop runs the strings inside the paragraphs are reset to their initial values, so it looks like nothing has been added to the “admit” and “refuse” lists, except for the very last value in the array.

I think that’s about it. Have you tried using browser developer tools to debug errors? These kinds of problems are usually fairly easy to diagnose by looking at the web console to see what errors are output.

All the best, and don’t hesitate to ask if you have more questions.

Thank you, that’s it!

I have tried using browser developer tools, but I get quite confused at the errors they throw up :-/ . I assume that will get better once I get more proficient in js.

@Wonderbird_Pointyshoes yes, absolutely. After a while you start to recognise patterns, both in the code, and the errors the code throws out. You’ll get there.