function flipcard_main() {
  var cardFront = document.getElementsByClassName("fcfront");
  var i;
  var flip;
  for (i = 0; i < cardFront.length; i++) {
    flip = document.createElement("div");
    flip.appendChild(document.createTextNode("flip"));
    flip.className = "fcflip";
    flip.addEventListener("click", event => {
      var flip = event.target;
      var front = flip.parentElement;
      var card = front.parentElement;
      card.style.transform = "rotateY(180deg)";
    });
    cardFront[i].appendChild(flip);
  };
  var cardBack = document.getElementsByClassName("fcback");
  var i;
  for (i = 0; i < cardBack.length; i++) {
    flip = document.createElement("div");
    flip.appendChild(document.createTextNode("flip"));
    flip.className = "fcflip";
    flip.addEventListener("click", event => {
      var flip = event.target;
      var front = flip.parentElement;
      var card = front.parentElement;
      card.style.transform = "rotateY(0deg)";
    });
    cardBack[i].appendChild(flip);
  };
};
flipcard_main();
