var zadanie1Start = function (question) {
  var body = $('<div class="zadanie1__questions"><div>').appendTo($("body"));
  var buttonDiv = $(
    '<center><div id="testBtn"></div></center><br><br><br><br><br><br>'
  ).appendTo($("body"));
  var button = $(
    '<input type="button" class="zadanie1__check" value="Проверить" id="btn" />'
  ).appendTo(buttonDiv);
  var countShowQuestion = 6;

  var countAnswer = [];

  var showQuestion = function () {
    countAnswer = [];
    body.html("");
    for (el = 0; el < countShowQuestion; el++) {
      j = Math.random();
      countAnswer.push(0);
      body.append(
        "<div class='zadanie1__question'><div id='q" +
          el +
          "'>" +
          (el + 1) +
          " " +
          question[el].question +
          "<br></div><div id='r" +
          el +
          "'></div></div>"
      );
      $(
        '<input type="radio" value="' +
          el +
          '" name="q' +
          el +
          '"/> ' +
          question[el].answer1 +
          "<br />"
      )
        .appendTo("#q" + el)
        .click(function () {
          if (question[this.value].answer == 1) countAnswer[this.value] = 1;
          else countAnswer[this.value] = 0;
        });
      $(
        '<input type="radio" value="' +
          el +
          '" name="q' +
          el +
          '"/> ' +
          question[el].answer2 +
          "<br />"
      )
        .appendTo("#q" + el)
        .click(function () {
          if (question[this.value].answer == 2) countAnswer[this.value] = 1;
          else countAnswer[this.value] = 0;
        });
      $(
        '<input type="radio" value="' +
          el +
          '" name="q' +
          el +
          '"/> ' +
          question[el].answer3 +
          "<br />"
      )
        .appendTo("#q" + el)
        .click(function () {
          if (question[this.value].answer == 3) countAnswer[this.value] = 1;
          else countAnswer[this.value] = 0;
        });
      $(
        '<input type="radio" value="' +
          el +
          '" name="q' +
          el +
          '"/> ' +
          question[el].answer4 +
          "<br />"
      )
        .appendTo("#q" + el)
        .click(function () {
          if (question[this.value].answer == 4) countAnswer[this.value] = 1;
          else countAnswer[this.value] = 0;
        });
    }
  };

  showQuestion();

  button.click(function () {
    $("#btn").css("display", "none"); //Скрыть кнопку после нажатия
    var count = 0;
    for (i in countAnswer) {
      if (countAnswer[i] == 1) {
        count++;
        $("#r" + i).html("Верно!");
        $("#r" + i).css("text-align", "center");
        $("#r" + i).css("background-color", "#00bc0fa6");
      } else {
        $("#r" + i).html("Неверно!");
        $("#r" + i).css("background-color", "#f9000082");
        $("#r" + i).css("text-align", "center");
      }
    }
    var result = (count / countAnswer.length) * 100;
    if (result < 75) {
      alert("Вы не готовы. Повторите пройденный материал.");
      var buttonNext = $(
        '<a id="zadanie-2" class="menubox_header_white" href="razdel1.html" target="content">Повторить теорию</a>'
      ).insertBefore(button);
    }

    if (result >= 75) {
      var buttonNext = $(
        '<a id="zadanie-2" class="menubox_header_white" href="zadanie2.html" target="content">Следующее задание</a>'
      ).insertBefore(button);
    }
    // if (result >= 50 && result < 69) alert("Удовлетворительно.");
    // if (result >= 70 && result < 89) alert("Оценка - хорошо.");
    // if (result >= 90) alert("Отлично! Можете показать оценку преподавателю.");
  });
};
var zadanie1 = {
  0: {
    question: "На рисунке 1:",
    answer1: "SFP модуль",
    answer2: "SFP+ модуль",
    answer3: "SFP+ LTE модули",
    answer4: "XENPAK модуль",
    answer: 2,
  },
  1: {
    question: "На рисунке 2:",
    answer1: "SFP модуль",
    answer2: "SFP+ модуль",
    answer3: "SFP+ LTE модули",
    answer4: "XENPAK модуль",
    answer: 1,
  },
  2: {
    question: "На рисунке 3:",
    answer1: "SFP модуль",
    answer2: "SFP+ модуль",
    answer3: "SFP LTE / SFP+ LTE модули",
    answer4: "XENPAK модуль",
    answer: 2,
  },
  3: {
    question: "На рисунке 4:",
    answer1: "XFP модуль",
    answer2: "SFP28 модуль",
    answer3: "X2 модуль",
    answer4: "XENPAK модуль",
    answer: 3,
  },
  4: {
    question: "На рисунке 5:",
    answer1: "XFP модуль",
    answer2: "XENPAK модуль",
    answer3: "X2 модуль",
    answer4: "QSFP28 модуль",
    answer: 1,
  },
  5: {
    question: "На рисунке 6:",
    answer1: " X2 модуль",
    answer2: "XFP модуль",
    answer3: "SFP+ модуль",
    answer4: "XENPAK модуль",
    answer: 1,
  },
};
