Q:

Adding Pagination limit

I'm newbie at JavaScript and I'm building some scripts to increase my skills.
I'm trying to build a pagination script in pure JavaScript, the script is working, but I would like block the forward link when the user reaches the pagination limit. I already tried to create a condition to prevent this situation, but is not working.
My code:
var col = document.getElementsByClassName('square');

    //Limit of squares to be shown

    var begin = 0;
    var end = 3;

    //Show the first three squares

    changePage("forward", 0, 0);
    changePage("back", 0, 0);

    function removeCols() {
      for (var i = 0; i < col.length; i++) {
        col[i].style = "display:none";
      }
    }

    //Forward and previous links

    document.getElementsByClassName('forward')[0].onclick = function() {
      changePage("forward", (col.length - 3), col.length);
    };
    document.getElementsByClassName('previous')[0].onclick = function() {
      changePage("previous", 0, 3);
    };

    //Function to change the pagination page

    function changePage(move, valueBegin, valueEnd) {

      //This if statement checks if the user reached the pagination limit

      if (document.getElementById('page').value == "" + valueBegin + valueEnd) {
        return false;
      } else {
        removeCols();
        if (move == "forward") {
          var forwardBegin = begin += 3;
          var forwardEnd = end += 3;
          moveIt(forwardBegin, forwardEnd);
          document.getElementById('page').value = "" + forwardBegin + forwardEnd;
        } else {
          var previousBegin = begin -= 3;
          var previousEnd = end -= 3;
          moveIt(previousBegin, previousEnd);
          document.getElementById('page').value = "" + previousBegin + previousEnd;
        }
      }
    }

    //Change page

    function moveIt(begin, end) {
      for (var i = begin; i < end; ++i) {
        var item = col[i];
        if (item) {
          item.style = "display:inline-block";
        }
      }
    }

Jsfiddle:
https://jsfiddle.net/eyqv5j9w/2/

A:

@Serg is right in that the way you're storing the current page is causing the paging to be incorrect.
I forked your example and very much simplified things. I made it hide the previous/forward links when you're on the first/last page. I also put the # of squares to be shown per page into it's own variable so it's easy to modify.
https://jsfiddle.net/2nzvyLvw/3/
Here are the main parts I changed:
  var col = document.getElementsByClassName('square');
  var forward = document.getElementsByClassName('forward')[0];
  var previous = document.getElementsByClassName('previous')[0];
  var page = 0;
  var squaresPerPage = 3;

  //Show the first page
  changePage(0, squaresPerPage);

  forward.onclick = function() {
    page++;
    var startingSquare = page * squaresPerPage;
    changePage(startingSquare, startingSquare + squaresPerPage);
  };
  previous.onclick = function() {
    page--;
    var startingSquare = page * squaresPerPage;
    changePage(startingSquare, startingSquare + squaresPerPage);
  };

  function changePage(valueBegin, valueEnd) {
    removeCols();
    moveIt(valueBegin, valueEnd);

    // hide forward link if on last page
    if (valueEnd >= col.length) {
      forward.style = "display: none";
    } else {
      forward.style = "display: inline";
    }
    // hide previous link if on first page
    if (valueBegin <= 0) {
      previous.style = "display: none";
    } else {
      previous.style = "display: inline";
    }
  }

