Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var eulerQuestions = [];
- var questionCount = 0;
- var currentAnswer = "?";
- function is_correct(answer) {
- if (currentAnswer == "?") {
- alert("Sorry I do not know the answer");
- return;
- }
- var yourHash = md5(answer);
- if (yourHash == currentAnswer) {
- alert('Correct');
- } else {
- alert('Incorrect');
- }
- }
- function initialize_euler() {
- eulerDb = eulerDb.replace(/(?:rn|r|n)/g, '$NEW');
- var matches;
- var re = /Problems+d+.*?=+(.*?)Answer:s+([a-f0-9]+|?)/g;
- while (matches = re.exec(eulerDb)) {
- eulerQuestions.push([matches[1], matches[2]]);
- questionCount++;
- }
- build_question_buttons();
- render_question(0);
- }
- function build_question_buttons() {
- var button_temp = '<a onclick="render_question($1);" class="btn btn-default" role="button">$2</a>';
- var generated_html = '';
- for (var i = 0; i < questionCount; i++) {
- var temp_str = button_temp.replace('$1', i);
- temp_str = temp_str.replace('$2', i + 1);
- generated_html += temp_str;
- }
- document.getElementById("questionButtons").innerHTML = generated_html;
- }
- function render_question(questionId) {
- var question = eulerQuestions[questionId][0].replace(/(?:$NEW)/g, 'n');
- currentAnswer = eulerQuestions[questionId][1];
- if (currentAnswer == "?") {
- question += "nnNote: Answer is not available."
- }
- document.getElementById("question").innerHTML = question;
- document.getElementById("questionNumber").innerHTML = "Problem " + (questionId + 1);
- }
- <div class="container">
- <div class="container">
- <div class="row well">
- <div class="col-md-4 well well-sm pre-scrollable">
- <div class="btn-toolbar" role="toolbar">
- <div class="button-container" id="questionButtons">
- </div>
- </div>
- </div>
- <div class="col-md-8">
- <form role="form" id="questionForm">
- <div class="form-group">
- <label id="questionNumber">Problem 01</label>
- </div>
- <div class="form-group">
- <pre id="question" style="">
- </pre>
- </div>
- <div class="form-group">
- <label>Answer:</label>
- <input type="text" class="form-control" id="answer">
- </div>
- <a class="btn btn-default" role="button" onclick="is_correct(document.getElementById('answer').value)">
- Test Answer
- </a>
- </form>
- </div>
- </div>
- </div>
- </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement