Javascript.RU

Создать новую тему Ответ
 
Опции темы Искать в теме
  #11 (permalink)  
Старый 18.06.2018, 00:44
Аватар для рони
Профессор
Отправить личное сообщение для рони Посмотреть профиль Найти все сообщения от рони
 
Регистрация: 27.05.2010
Сообщений: 33,070

Хомяк,
<!DOCTYPE html>
<html lang="ru-RU">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Тест на время</title>
<style>
body{
    font-family:verdana;
    color:#444;
}
#option1,#option2,#option3{
    display:none;
    margin-bottom: 10px;
}
.kp{
    text-decoration: none;
    font-size: 20px;
    margin-right: 20px;
    color: #fff;
    background: #333333;
    padding: 4px 8px;
    border: 0;
    cursor: pointer;
}
.nach{
    text-decoration: none;
    font-size: 20px;
    margin-right: 20px;
    color: #fff;
    background: #ff8000;
    padding: 4px 8px;
    border: 0;
    cursor: pointer;
}
 #result > p{
    font-size: 12px;
 }

</style>
<script type="text/javascript">
     function mix(mixArray) {
      var index, valueIndex;
      for (var i=0; i<=mixArray.length-1; i++) {
        index = Math.floor(Math.random()*i);
        valueIndex = mixArray[index];
        mixArray[index] = mixArray[i];
        mixArray[i] = valueIndex;
      }
      return mixArray;
    }

    //Массив вопросов и ответа
    var data_array = [
      ["Сколько сантиметров в метре?","10","1024","100",3,"комм1"],
      ["Перевод слова: Hello","Как дела?","Привет","Ты",2,"комм2"],
      ["Перевод слова: Dog","Собака","Кошка","Дерево",1,"комм3"],
      ["Сколько месяцев в году?","10","11","12",3,"комм4"],
      ["Перевод слова: Tree","Три","Собака","Дерево",3,"комм5"],
      ["Перевод слова: Wall","Стена","Дом","Башня",1,"комм6"],
    ];

    mix(data_array);
    var plus = 0;
    var time = 60;
    var cur_answer = 0;
    var count_answer = 3;
    var intervalID;
    var err = [];
    function sec() {
        if(time<0) {
          window.clearTimeout(intervalID);
          cur_answer = count_answer;
          check()
        }
        else {
        document.getElementById('time').innerHTML=time + ' сек';
        time=time-1;
        intervalID = window.setTimeout(sec,1000);
        }
    }
function check(num) {
  if (num == 0) {
    document.getElementById("option1").style.display = "block";
    document.getElementById("option2").style.display = "block";
    document.getElementById("option3").style.display = "block";
    document.getElementById("question").style.display = "block";
    document.getElementById("option1").innerHTML = data_array[cur_answer][1];
    document.getElementById("option2").innerHTML = data_array[cur_answer][2];
    document.getElementById("option3").innerHTML = data_array[cur_answer][3];
    document.getElementById("question").innerHTML = data_array[cur_answer][0];
    document.getElementById("start").style.display = "none";
    sec();
  } else {
    if (num == data_array[cur_answer][4]) {
      plus++;
    }
    else {
     num && err.push([cur_answer,num])
    };
    cur_answer++;
    if (cur_answer < count_answer) {
      document.getElementById("option1").innerHTML = data_array[cur_answer][1];
      document.getElementById("option2").innerHTML = data_array[cur_answer][2];
      document.getElementById("option3").innerHTML = data_array[cur_answer][3];
      document.getElementById("question").innerHTML = data_array[cur_answer][0];
    } else {
      document.getElementById("end").style.display = "inline";
      time = -1;
      document.getElementById("option1").style.display = "none";
      document.getElementById("option2").style.display = "none";
      document.getElementById("option3").style.display = "none";
      document.getElementById("question").style.display = "none";
      var percent = Math.round(plus / count_answer * 100);
      var percent =  Math.round(plus/count_answer*100);
      var res = 'Плохо!';
      if(percent>70) res = 'Хорошо!';
      if(percent==100) res = 'Отлично!';
      var text = err.reduce(function(a, b) {
      var cur_answer = b[0], num = b[1], question = data_array[cur_answer], ok = question[4];
return a + "<br>Вопрос №" +(cur_answer + 1) +" " + question[0] + "<br>Ваш ответ: " + question[num] +"<br>Правильный ответ: " + question[ok]
},"");

      document.getElementById('result').innerHTML='Правильных ответов: ' + plus + ' из ' + count_answer + ' (' + percent + '%)<br>' + res + '<p>' + text +'</p>';    }
  }
};
</script>
</head>
<body>
    <center>
        <p style="font-size: 38px;font-weight: bold;padding-top: 2px;" id="time"></p>
        <p style="font-size: 38px;font-weight: bold;padding-top: 2px;" id="result"></p>

        <p style="font-size: 38px;font-weight: bold;padding-top: 2px;" id="question"></p>

        <button onclick="check(1)" class="kp" id="option1"></button>

        <button onclick="check(2)" class="kp" id="option2"></button>

        <button onclick="check(3)" class="kp" id="option3"></button>

    </center><br>
    <center>
        <button id="start" class="kp" onclick="check(0)">Приступить к тесту</button>
        <script type="text/javascript"> var curent_url = document.URL; document.write("<a id='end' style='display: none;' class='nach' href='" + curent_url + "'>Начать сначала</a>"); </script>
    </center><br><br>
</body>
</html>
Ответить с цитированием
Ответ



Опции темы Искать в теме
Искать в теме:

Расширенный поиск


Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
Таймер обратного отсчета до события boypush Элементы интерфейса 17 04.05.2015 23:35
Как сделать таймер обратного отсчета который бы запускался при открытии сайта ibutterfly777 Оффтопик 0 29.10.2014 10:55
таймер обратного отсчёта AdDa Элементы интерфейса 10 05.11.2012 22:06
Один обработчик для нескольких кнопок! frundik Элементы интерфейса 2 10.07.2012 15:30
Таймер для слайдера (jQuery) RamPi Events/DOM/Window 0 23.05.2011 14:52