bushido2014
@bushido2014

JQuery Quiz Тест, как получить результаты?

Привет всем, погуглил по нету и нашел тут скрипт Dynamic Quiz JQuery, хочу на сайт Lading Page его установить как сделать все данные ответов суммировались и перевелись в процентах(умножались на 10)

(function() {
  var questions = [{
    question: "1. Какие каналы продаж вы используйте?",
    choices: ["Точки продаж 0,3", "Интернет продажи 0,3", "Продажи через менеджеров 0,3", "Продаю сам 0,1"],
    correctAnswer: 2
  }, {
    question: "2. Какие каналы вы используйте для привлечения клиентов?",
    choices: ["Интернет-маркетинг 0,25", "Продажи по телефону 0,25 ", "Реклама и PR 0,25",
     "Выставки, тендеры 0,25", 
    "Не используем ни один из выше перечисленных каналов 0 "],
    correctAnswer: 4
  }, {
    question: "3. Через какие интернет каналы вы продвигаете ваш бизнес:",
    choices: ["Сайт и SEO продвижение 0,2", "Социальные сети 0,2", "E-mail маркетинг 0,2",
     "Не один из выше перечисленных 0", "Все из выше перечисленных 0,4"],
    correctAnswer: 0
  }, {
    question: "4. Продажи вашей компании ведутся следующим образом:",
    choices: ["Не понимаю, как но продажи вроде бы есть 0", "Менеджеры делают холодные звонки 0,1", "Через друзей, знакомых и рекомендации 0,1", 
    "Есть определённые задачи и план у менеджеров 0,3", "e. Есть план продаж, скрипты, коммерческие предложения, ведется воронка продаж, процент продаж растет 0,5"],
    correctAnswer: 8
  }, {
    question: "5. Ваша база клиентов ведется:",
    choices: ["Не ведется 0", "В ежедневнике 0,1", "В Excel-е 0,2", "В CRM системе 0,7"],
    correctAnswer: 7
  }, {
    question: "6. У нашей компании есть следующие цели:",
    choices: ["Целей нет, двигаемся интуитивно 0",
     "Цель рост продаж 0,3", "Есть маркетинговый план с этапами достижения цели 0,7"],
    correctAnswer: 7
  }, {
    question: "7. Знаете ли вы откуда приходят ваши клиенты?",
    choices: ["Не знаю 0 ", "По рекомендациям и знакомым 0,1", "По рекомендациям и знакомым 0,1",
     "Через рекламу 0,3", 
     "Четко отслеживаем каналы по которым приходят клиенты ( сайт, SMM, SEO, Google Ads, e-mai marketing, Youtube, наружная реклама) 0,6"],
    correctAnswer: 6
  }, {
    question: "8. В случае увольнения ключевого сотрудника или форс мажора, у вас:",
    choices: ["Срываются сроки и качество 0 ", "Блокируется деятельность компании 0", 
    "Все делаю сам 0",
     "Через рекламу 0,3", 
     "Четко прописаны шаги, решения, которые позволяют спокойно продолжить процесс 1"],
    correctAnswer: 5
  }, {
    question: "9. Какой рекламный бюджет вы используйте в месяц? ",
    choices: ["Нет бюджета на продвижение 0", "До 2000 лей в месяц 0,1", "2001 – 5000 лей 0,2",
     "5001 – 10 000 лей 0,3", 
     "Более 10 000 лей в месяц 0,4"],
    correctAnswer: 8
  }, {
    question: "10.  Вы довольны результатами ваших продаж?",
    choices: ["Да 1", "Нет 0 "],
    correctAnswer: 12
  }];
  
  var questionCounter = 0; //Tracks question number
  var selections = []; //Array containing user choices
  var quiz = $('#quiz'); //Quiz div object
  
  // Display initial question
  displayNext();
  
  // Click handler for the 'next' button
  $('#next').on('click', function (e) {
    e.preventDefault();
    
    // Suspend click listener during fade animation
    if(quiz.is(':animated')) {        
      return false;
    }
    choose();
    
    // If no user selection, progress is stopped
    if (isNaN(selections[questionCounter])) {
      alert('Please make a selection!');
    } else {
      questionCounter++;
      displayNext();
    }
  });
  
  // Click handler for the 'prev' button
  $('#prev').on('click', function (e) {
    e.preventDefault();
    
    if(quiz.is(':animated')) {
      return false;
    }
    choose();
    questionCounter--;
    displayNext();
  });
  
  // Click handler for the 'Start Over' button
  $('#start').on('click', function (e) {
    e.preventDefault();
    
    if(quiz.is(':animated')) {
      return false;
    }
    questionCounter = 0;
    selections = [];
    displayNext();
    $('#start').hide();
  });
  
  // Animates buttons on hover
  $('.button').on('mouseenter', function () {
    $(this).addClass('active');
  });
  $('.button').on('mouseleave', function () {
    $(this).removeClass('active');
  });
  
  // Creates and returns the div that contains the questions and 
  // the answer selections
  function createQuestionElement(index) {
    var qElement = $('<div>', {
      id: 'question'
    });
    
    // var header = $('<h2>Question ' + (index + 1) + ':</h2>');
    // qElement.append(header);
    
    var question = $('<p>').append(questions[index].question);
    qElement.append(question);
    
    var radioButtons = createRadios(index);
    qElement.append(radioButtons);
    
    return qElement;
  }
  
  // Creates a list of the answer choices as radio inputs
  function createRadios(index) {
    var radioList = $('<ul class="radioList">');
    var item;
    var input = '';
    for (var i = 0; i < questions[index].choices.length; i++) {
      item = $('<li>');
      input = '<input type="radio" name="answer" value=' + i + ' />';
      input += questions[index].choices[i];
      item.append(input);
      radioList.append(item);
    }
    return radioList;
  }
  
  // Reads the user selection and pushes the value to an array
  function choose() {
    selections[questionCounter] = +$('input[name="answer"]:checked').val();
  }
  
  // Displays next requested element
  function displayNext() {
    quiz.fadeOut(function() {
      $('#question').remove();
      
      if(questionCounter < questions.length){
        var nextQuestion = createQuestionElement(questionCounter);
        quiz.append(nextQuestion).fadeIn();
        if (!(isNaN(selections[questionCounter]))) {
          $('input[value='+selections[questionCounter]+']').prop('checked', true);
        }
        
        // Controls display of 'prev' button
        if(questionCounter === 1){
          $('#prev').show();
        } else if(questionCounter === 0){
          
          $('#prev').hide();
          $('#next').show();
        }
      }else {
        var scoreElem = displayScore();
        quiz.append(scoreElem).fadeIn();
        $('#next').hide();
        $('#prev').hide();
        $('#start').show();
      }
    });
  }
  
  // Computes score and returns a paragraph element to be displayed
  function displayScore() {
    var score = $('<p>',{id: 'question'});
    
    var numCorrect = 0;
    for (var i = 0; i < selections.length; i++) {
      if (selections[i] === questions[i].correctAnswer) {
        numCorrect++;
      }
    }
    
    score.append('Ваш маркетинг эффективен на  ' + numCorrect + ' %');
    return score;
  }
})();
  • Вопрос задан
  • 803 просмотра
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы