Access authentication using loop

Greetings to all

I need your support for this problem, because I am a newbie in JavaScript and i’m currently stuck!


1.) each user has the number of homework they’ve done. For example a user submitted homework #10 then he/she has access for homework 11 and 12 etc.

2.) In my main page or html file, each video has each specific div/container with the class of .lesson-1 - .lesson-55.

3.) If the student submitted Homework #20 for example, then the video 1 to video 22 are display and accessible to my page and the rest are display: none or hidden.


<div class="lesson lesson-1">video 55</div>

      ........ up to

<div class="lesson lesson-55">video 1</div>


function User(email, pass, hw) { = email;

  this.pass = pass;

  this.hw = hw;


// Indiviadual Users

let user1 = new User('',  '123',  53);

let user2 = new User('',  '246', 50);

// User Groups

let users = [user1, user2];

function prerequisites() {

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

    for (let n = 1; n <= users[i].hw + 2; n++) {

      // this function returns value of 1 to 55 for user1 and  1 - 52 for user2.

     // document.querySelector('.lesson-' + n).style.display = 'none';
     // document.querySelector('.lesson-' + n).style.display = 'block';




I appreciate who ever help for this.

This is a practice for me.

Hello there.

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.

Note: Backticks are not single quotes.


1 Like