From b15f76701e22b095bdded772dd1ade286bbf69cc Mon Sep 17 00:00:00 2001 From: Vivek Santayana Date: Wed, 17 Aug 2022 16:34:59 +0100 Subject: [PATCH] Code clean up: redundant semicolons Made variable declaration style in for loops consistent --- ref-test/app/admin/static/js/script.js | 131 ++--- ref-test/app/editor/static/js/script.js | 2 +- ref-test/app/quiz/static/js/quiz.js | 686 ++++++++++++------------ ref-test/app/quiz/static/js/script.js | 46 +- ref-test/app/root/js/script.js | 46 +- 5 files changed, 458 insertions(+), 453 deletions(-) diff --git a/ref-test/app/admin/static/js/script.js b/ref-test/app/admin/static/js/script.js index 1fd1391..3b45528 100644 --- a/ref-test/app/admin/static/js/script.js +++ b/ref-test/app/admin/static/js/script.js @@ -1,25 +1,25 @@ // Menu Highlight Scripts -const menuItems = document.getElementsByClassName('nav-link'); +const menuItems = document.getElementsByClassName('nav-link') for(let i = 0; i < menuItems.length; i++) { if(menuItems[i].pathname == window.location.pathname) { - menuItems[i].classList.add('active'); + menuItems[i].classList.add('active') } } -const dropdownItems = document.getElementsByClassName('dropdown-item'); +const dropdownItems = document.getElementsByClassName('dropdown-item') for(let i = 0; i< dropdownItems.length; i++) { if(dropdownItems[i].pathname == window.location.pathname) { - dropdownItems[i].classList.add('active'); - $( "#" + dropdownItems[i].id ).closest( '.dropdown' ).find('.dropdown-toggle').addClass('active'); + dropdownItems[i].classList.add('active') + $( "#" + dropdownItems[i].id ).closest( '.dropdown' ).find('.dropdown-toggle').addClass('active') } } // General Post Method Form Processing Script $('form.form-post').submit(function(event) { - var $form = $(this); - var data = $form.serialize(); - var url = $(this).prop('action'); - var rel_success = $(this).data('rel-success'); + var $form = $(this) + var data = $form.serialize() + var url = $(this).prop('action') + var rel_success = $(this).data('rel-success') $.ajax({ url: url, @@ -28,25 +28,25 @@ $('form.form-post').submit(function(event) { dataType: 'json', success: function(response) { if (response.redirect_to) { - window.location.href = response.redirect_to; + window.location.href = response.redirect_to } else { - window.location.href = rel_success; + window.location.href = rel_success } }, error: function(response) { - error_response(response); + error_response(response) } - }); + }) - event.preventDefault(); -}); + event.preventDefault() +}) // Form Upload Questions - Special case, needs to handle files. $('form[name=form-upload-questions]').submit(function(event) { - var $form = $(this); - var data = new FormData($form[0]); + var $form = $(this) + var data = new FormData($form[0]) var file = $('input[name=data_file]')[0].files[0] data.append('file', file) @@ -57,21 +57,21 @@ $('form[name=form-upload-questions]').submit(function(event) { processData: false, contentType: false, success: function(response) { - window.location.reload(); + window.location.reload() }, error: function(response) { - error_response(response); + error_response(response) } - }); + }) - event.preventDefault(); -}); + event.preventDefault() +}) // Edit and Delete Test Button Handlers $('.test-action').click(function(event) { - let id = $(this).data('id'); - let action = $(this).data('action'); + let id = $(this).data('id') + let action = $(this).data('action') if (action == 'delete' || action == 'start' || action == 'end') { $.ajax({ @@ -80,25 +80,25 @@ $('.test-action').click(function(event) { data: JSON.stringify({'id': id, 'action': action}), contentType: 'application/json', success: function(response) { - window.location.href = '/admin/tests/'; + window.location.href = '/admin/tests/' }, error: function(response){ - error_response(response); + error_response(response) }, - }); + }) } else if (action == 'edit') { window.location.href = `/admin/test/${id}/` } - event.preventDefault(); -}); + event.preventDefault() +}) // Edit Dataset Button Handlers $('.edit-question-dataset').click(function(event) { - var id = $(this).data('id'); - var action = $(this).data('action'); - var disabled = $(this).hasClass('disabled'); + var id = $(this).data('id') + var action = $(this).data('action') + var disabled = $(this).hasClass('disabled') if ( !disabled ) { if (action == 'delete') { @@ -111,25 +111,27 @@ $('.edit-question-dataset').click(function(event) { }), contentType: 'application/json', success: function(response) { - window.location.reload(); + window.location.reload() }, error: function(response){ - error_response(response); + error_response(response) }, - }); + }) } else if (action == 'edit') { window.location.href = `/admin/editor/${id}/` + } else if (action == 'view') { + window.location.href = `/admin/view/${id}` } else if (action == 'download') { window.location.href = `/admin/settings/questions/download/${id}/` } - }; - event.preventDefault(); -}); + } + event.preventDefault() +}) function error_response(response) { - const $alert = $("#alert-box"); - $alert.html(''); + const $alert = $("#alert-box") + $alert.html('') if (typeof response.responseJSON.error === 'string' || response.responseJSON.error instanceof String) { $alert.html(` @@ -138,18 +140,18 @@ function error_response(response) { ${response.responseJSON.error} - `); + `) } else if (response.responseJSON.error instanceof Array) { var output = '' - for (var i = 0; i < response.responseJSON.error.length; i ++) { + for (let i = 0; i < response.responseJSON.error.length; i ++) { output += ` - `; - $alert.html(output); + ` + $alert.html(output) } } @@ -167,20 +169,20 @@ $('#dismiss-cookie-alert').click(function(event){ }, dataType: 'json', success: function(response){ - console.log(response); + console.log(response) }, error: function(response){ - console.log(response); + console.log(response) } }) - event.preventDefault(); + event.preventDefault() }) // Script for Result Actions $('.result-action-buttons').click(function(event){ - var id = $(this).data('id'); + var id = $(this).data('id') if ($(this).data('result-action') == 'generate') { $.ajax({ @@ -190,13 +192,13 @@ $('.result-action-buttons').click(function(event){ contentType: 'application/json', dataType: 'html', success: function(response) { - var display_window = window.open(); - display_window.document.write(response); + var display_window = window.open() + display_window.document.write(response) }, error: function(response){ - error_response(response); + error_response(response) }, - }); + }) } else { var action = $(this).data('result-action') $.ajax({ @@ -206,23 +208,23 @@ $('.result-action-buttons').click(function(event){ contentType: 'application/json', success: function(response) { if (action == 'delete') { - window.location.href = '/admin/results/'; - } else window.location.reload(); + window.location.href = '/admin/results/' + } else window.location.reload() }, error: function(response){ - error_response(response); + error_response(response) }, - }); + }) } - event.preventDefault(); -}); + event.preventDefault() +}) // Script for Deleting Time Adjustment $('.adjustment-delete').click(function(event){ - var user_code = $(this).data('user_code'); - var location = window.location.href; + var user_code = $(this).data('user_code') + var location = window.location.href location = location.replace('#', '') $.ajax({ @@ -231,12 +233,15 @@ $('.adjustment-delete').click(function(event){ data: JSON.stringify({'user_code': user_code}), contentType: 'application/json', success: function(response) { - window.location.reload(); + window.location.reload() }, error: function(response){ - error_response(response); + error_response(response) }, - }); + }) + + event.preventDefault() +}) event.preventDefault(); }); \ No newline at end of file diff --git a/ref-test/app/editor/static/js/script.js b/ref-test/app/editor/static/js/script.js index bba3bde..f9a08ad 100644 --- a/ref-test/app/editor/static/js/script.js +++ b/ref-test/app/editor/static/js/script.js @@ -57,7 +57,7 @@ function error_response(response) { `); } else if (response.responseJSON.error instanceof Array) { var output = '' - for (var i = 0; i < response.responseJSON.error.length; i ++) { + for (let i = 0; i < response.responseJSON.error.length; i ++) { output += ` ` } - $question_options.html(options_output); - let skipped = count_questions(-1); - let answered = count_questions(2); - let flagged = count_questions(1); + $question_options.html(options_output) + let skipped = count_questions(-1) + let answered = count_questions(2) + let flagged = count_questions(1) - $progress_skipped.prop('title', `Skipped: ${skipped}`); - $progress_skipped.prop('aria-valuenow', skipped); - $progress_skipped.css('width', `${skipped}%`); - $skipped_count.text(`Skipped: ${skipped}`); + $progress_skipped.prop('title', `Skipped: ${skipped}`) + $progress_skipped.prop('aria-valuenow', skipped) + $progress_skipped.css('width', `${skipped}%`) + $skipped_count.text(`Skipped: ${skipped}`) if (skipped < 1) { $skipped_count.fadeOut() } else { $skipped_count.fadeIn() } - $progress_flagged.prop('title', `Flagged: ${flagged}`); - $progress_flagged.prop('aria-valuenow', flagged); - $progress_flagged.css('width', `${flagged}%`); - $flagged_count.text(`Flagged: ${flagged}`); + $progress_flagged.prop('title', `Flagged: ${flagged}`) + $progress_flagged.prop('aria-valuenow', flagged) + $progress_flagged.css('width', `${flagged}%`) + $flagged_count.text(`Flagged: ${flagged}`) if (flagged < 1) { $flagged_count.fadeOut() } else { $flagged_count.fadeIn() } - $progress_answered.prop('title', `Answered: ${answered}`); - $progress_answered.prop('aria-valuenow', answered); - $progress_answered.css('width', `${answered}%`); - $answered_count.text(`Answered: ${answered}`); + $progress_answered.prop('title', `Answered: ${answered}`) + $progress_answered.prop('aria-valuenow', answered) + $progress_answered.css('width', `${answered}%`) + $answered_count.text(`Answered: ${answered}`) if (answered < 1) { $answered_count.fadeOut() } else { $answered_count.fadeIn() } - $question_title.focus(); - $(window).scrollTop(0); + $question_title.focus() + $(window).scrollTop(0) } function check_answered() { - var question = questions[current_question]; - var name = question.q_no; + var question = questions[current_question] + var name = question.q_no if (question_status[current_question] == 0 || question_status[current_question] == -1) { if (!$(`input[name='${name}']:checked`).val()) { - question_status[current_question] = -1; + question_status[current_question] = -1 } else { - question_status[current_question] = 2; + question_status[current_question] = 2 } - window.localStorage.setItem('question_status', JSON.stringify(question_status)); + window.localStorage.setItem('question_status', JSON.stringify(question_status)) } } function check_flag() { if (!(current_question in question_status)) { - question_status[current_question] = 0; - window.localStorage.setItem('question_status', JSON.stringify(question_status)); + question_status[current_question] = 0 + window.localStorage.setItem('question_status', JSON.stringify(question_status)) } switch (question_status[current_question]) { case -1: - $nav_flag.removeClass().addClass('btn btn-danger progress-bar-striped'); - $nav_flag.prop("title", "Question Incomplete. Click to flag for revision."); - break; + $nav_flag.removeClass().addClass('btn btn-danger progress-bar-striped') + $nav_flag.prop("title", "Question Incomplete. Click to flag for revision.") + break case 1: - $nav_flag.removeClass().addClass('btn btn-warning'); - $nav_flag.prop("title", "Question Flagged for revision. Click to un-flag."); - break; + $nav_flag.removeClass().addClass('btn btn-warning') + $nav_flag.prop("title", "Question Flagged for revision. Click to un-flag.") + break case 2: - $nav_flag.removeClass().addClass('btn btn-success'); - $nav_flag.prop("title", "Question Answered. Click to flag for revision."); - break; + $nav_flag.removeClass().addClass('btn btn-success') + $nav_flag.prop("title", "Question Answered. Click to flag for revision.") + break default: - $nav_flag.removeClass().addClass('btn btn-secondary'); - $nav_flag.prop("title", "Question Un-Flagged. Click to flag for revision."); + $nav_flag.removeClass().addClass('btn btn-secondary') + $nav_flag.prop("title", "Question Un-Flagged. Click to flag for revision.") } } @@ -457,31 +457,31 @@ function build_navigator() { $nav_container.html('') var output = '' for (let i = 0; i < questions.length; i ++) { - let add_class, add_href, add_status = ''; + let add_class, add_href, add_status = '' switch (question_status[i]) { case -1: - add_class = 'btn-danger progress-bar-striped'; - add_href = 'href="#"'; - add_status = 'Incomplete'; - break; + add_class = 'btn-danger progress-bar-striped' + add_href = 'href="#"' + add_status = 'Incomplete' + break case 1: - add_class = 'btn-warning'; - add_href = 'href="#"'; - add_status = 'Flagged'; - break; + add_class = 'btn-warning' + add_href = 'href="#"' + add_status = 'Flagged' + break case 2: - add_class = 'btn-success'; - add_href = 'href="#"'; - add_status = 'Answered'; - break; + add_class = 'btn-success' + add_href = 'href="#"' + add_status = 'Answered' + break default: - add_class = 'btn-secondary disabled'; - add_href = ''; - add_status = 'Unseen'; + add_class = 'btn-secondary disabled' + add_href = '' + add_status = 'Unseen' } - output += `Q${i + 1}`; + output += `Q${i + 1}` } - $nav_container.html(output); + $nav_container.html(output) } function update_navigator() { @@ -489,162 +489,162 @@ function update_navigator() { if (current_question in question_status) { switch (question_status[current_question]) { case -1: - button.removeClass().addClass("q-navigator-button btn btn-danger progress-bar-striped"); - button.prop("title", `Question ${current_question + 1}: Incomplete`); - break; + button.removeClass().addClass("q-navigator-button btn btn-danger progress-bar-striped") + button.prop("title", `Question ${current_question + 1}: Incomplete`) + break case 1: - button.removeClass().addClass("q-navigator-button btn btn-warning"); - button.prop("title", `Question ${current_question + 1}: Flagged`); - break; + button.removeClass().addClass("q-navigator-button btn btn-warning") + button.prop("title", `Question ${current_question + 1}: Flagged`) + break case 2: - button.removeClass().addClass("q-navigator-button btn btn-success"); - button.prop("title", `Question ${current_question + 1}: Answered`); - break; + button.removeClass().addClass("q-navigator-button btn btn-success") + button.prop("title", `Question ${current_question + 1}: Answered`) + break default: - button.removeClass().addClass("q-navigator-button btn btn-secondary disabled"); - button.prop("title", `Question ${current_question + 1}: Unseen`); + button.removeClass().addClass("q-navigator-button btn btn-secondary disabled") + button.prop("title", `Question ${current_question + 1}: Unseen`) } } } function start() { - $("#btn-start-quiz").fadeOut(); - $(".btn-quiz-return").fadeIn(); - $(".quiz-console").fadeIn(); - $("#quiz-settings").fadeOut(); - $("#quiz-navigator").fadeOut(); - $(".quiz-start-text").fadeOut(); + $("#btn-start-quiz").fadeOut() + $(".btn-quiz-return").fadeIn() + $(".quiz-console").fadeIn() + $("#quiz-settings").fadeOut() + $("#quiz-navigator").fadeOut() + $(".quiz-start-text").fadeOut() - questions = JSON.parse(window.localStorage.getItem('questions')); - total_questions = questions.length; - start_time = window.localStorage.getItem('start_time'); - time_limit = window.localStorage.getItem('time_limit'); + questions = JSON.parse(window.localStorage.getItem('questions')) + total_questions = questions.length + start_time = window.localStorage.getItem('start_time') + time_limit = window.localStorage.getItem('time_limit') - let get_answers = window.localStorage.getItem('answers'); + let get_answers = window.localStorage.getItem('answers') if (get_answers != null) { - answers = JSON.parse(get_answers); + answers = JSON.parse(get_answers) } - let get_status = window.localStorage.getItem('question_status'); + let get_status = window.localStorage.getItem('question_status') if (get_status != null) { - question_status = JSON.parse(get_status); + question_status = JSON.parse(get_status) } - render_question(); - build_navigator(); - check_flag(); + render_question() + build_navigator() + check_flag() if (time_limit != 'null' && time_limit != null) { - $("#q-timer-widget").fadeIn(); - time_remaining = get_time_remaining(); - clock = setInterval(timer, 1000); + $("#q-timer-widget").fadeIn() + time_remaining = get_time_remaining() + clock = setInterval(timer, 1000) } } function check_started() { - let questions = window.localStorage.getItem('questions'); - let time_limit = window.localStorage.getItem('time_limit'); + let questions = window.localStorage.getItem('questions') + let time_limit = window.localStorage.getItem('time_limit') let start_time = window.localStorage.getItem('start_time') if (questions != null && start_time != null && time_limit != null) { - start(); + start() } } function get_time_remaining() { - var end_time = new Date(time_limit).getTime(); - var _start_time = new Date().getTime(); - return end_time - _start_time; + var end_time = new Date(time_limit).getTime() + var _start_time = new Date().getTime() + return end_time - _start_time } function timer() { - var hours = Math.floor((time_remaining % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)); - var minutes = Math.floor((time_remaining % (1000 * 60 * 60)) / (1000 * 60)); - var seconds = Math.floor((time_remaining % (1000 * 60)) / 1000); + var hours = Math.floor((time_remaining % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)) + var minutes = Math.floor((time_remaining % (1000 * 60 * 60)) / (1000 * 60)) + var seconds = Math.floor((time_remaining % (1000 * 60)) / 1000) if (time_remaining > 0) { - var timer_display = ''; + var timer_display = '' if (hours > 0) { - timer_display = `${hours.toString()}:`; + timer_display = `${hours.toString()}:` } if (minutes > 0 || hours > 0) { if (minutes < 10) { - timer_display += `0${minutes.toString()}:`; + timer_display += `0${minutes.toString()}:` } else { - timer_display += `${minutes.toString()}:`; + timer_display += `${minutes.toString()}:` } } if (seconds < 10) { - timer_display += `0${seconds.toString()}`; + timer_display += `0${seconds.toString()}` } else { - timer_display += seconds.toString(); + timer_display += seconds.toString() } - $timer.html(timer_display); + $timer.html(timer_display) time_remaining -= 1000 } else { - $timer.html('Expired'); - clearInterval(clock); + $timer.html('Expired') + clearInterval(clock) stop() } } function stop() { - $quiz_render.fadeOut(); - $quiz_navigator.fadeOut(); - $quiz_timeout.fadeIn(); - $("#btn-toggle-navigator").addClass('disabled'); + $quiz_render.fadeOut() + $quiz_navigator.fadeOut() + $quiz_timeout.fadeIn() + $("#btn-toggle-navigator").addClass('disabled') $("#btn-toggle-settings").addClass('disabled') } function count_questions(status) { - output = 0; + output = 0 for (let i = 0; i < Object.keys(question_status).length; i++) { - key = Object.keys(question_status)[i]; + key = Object.keys(question_status)[i] if (question_status[key] == status){ - output ++; + output ++ } } - return output; + return output } // Variable Definitions -const id = window.localStorage.getItem('id'); +const id = window.localStorage.getItem('id') -var current_question = 0; -var total_questions = 0; -var question_status = {}; -var answers = {}; -var questions = []; -var time_limit, start_time, time_remaining; +var current_question = 0 +var total_questions = 0 +var question_status = {} +var answers = {} +var questions = [] +var time_limit, start_time, time_remaining -var display_settings = get_settings_from_storage(); +var display_settings = get_settings_from_storage() -const $quiz_settings = $("#quiz-settings"); -const $quiz_navigator = $("#quiz-navigator"); -const $quiz_render = $("#quiz-render"); -const $quiz_timeout = $("#quiz-timeout"); -const $nav_flag = $("#q-nav-flag"); -const $nav_next = $("#q-nav-next"); -const $nav_prev = $("#q-nav-prev"); -const $nav_container = $("#navigator-container"); -const $timer = $("#q-timer-display"); +const $quiz_settings = $("#quiz-settings") +const $quiz_navigator = $("#quiz-navigator") +const $quiz_render = $("#quiz-render") +const $quiz_timeout = $("#quiz-timeout") +const $nav_flag = $("#q-nav-flag") +const $nav_next = $("#q-nav-next") +const $nav_prev = $("#q-nav-prev") +const $nav_container = $("#navigator-container") +const $timer = $("#q-timer-display") var clock -var toggle_settings = false; -var toggle_navigator = false; +var toggle_settings = false +var toggle_navigator = false -const $question_title = $("#quiz-question-title"); -const $question_header = $("#quiz-question-header"); -const $question_text = $("#quiz-question-text"); -const $question_options = $("#quiz-question-options"); +const $question_title = $("#quiz-question-title") +const $question_header = $("#quiz-question-header") +const $question_text = $("#quiz-question-text") +const $question_options = $("#quiz-question-options") -const $progress_skipped = $("#skipped-bar"); -const $progress_answered = $("#answered-bar"); -const $progress_flagged = $("#flagged-bar"); -const $skipped_count = $("#skipped-count"); -const $answered_count = $("#answered-count"); -const $flagged_count = $("#flagged-count"); +const $progress_skipped = $("#skipped-bar") +const $progress_answered = $("#answered-bar") +const $progress_flagged = $("#flagged-bar") +const $skipped_count = $("#skipped-count") +const $answered_count = $("#answered-count") +const $flagged_count = $("#flagged-count") // Execution on Load -apply_settings(display_settings); -check_started(); \ No newline at end of file +apply_settings(display_settings) +check_started() \ No newline at end of file diff --git a/ref-test/app/quiz/static/js/script.js b/ref-test/app/quiz/static/js/script.js index ba30892..0dfdf97 100644 --- a/ref-test/app/quiz/static/js/script.js +++ b/ref-test/app/quiz/static/js/script.js @@ -1,21 +1,21 @@ $(document).ready(function() { $("#od-font-test").click(function(){ $("body").css("font-family", "opendyslexic3regular") - }); + }) $('.test-code-input').keyup(function() { - var input = $(this).val().split("-").join("").split("—").join(""); + var input = $(this).val().split("-").join("").split("—").join("") if (input.length > 0) { - input = input.match(new RegExp('.{1,4}', 'g')).join("—"); + input = input.match(new RegExp('.{1,4}', 'g')).join("—") } - $(this).val(input); - }); -}); + $(this).val(input) + }) +}) $('form[name=form-quiz-start]').submit(function(event) { - var $form = $(this); - var data = $form.serialize(); + var $form = $(this) + var data = $form.serialize() $.ajax({ url: window.location.pathname, @@ -24,21 +24,21 @@ $('form[name=form-quiz-start]').submit(function(event) { dataType: 'json', success: function(response) { var id = response.id - window.localStorage.setItem('id', id); - window.location.href = `/quiz/`; + window.localStorage.setItem('id', id) + window.location.href = `/quiz/` }, error: function(response) { - error_response(response); + error_response(response) } - }); + }) - event.preventDefault(); -}); + event.preventDefault() +}) function error_response(response) { - const $alert = $("#alert-box"); - $alert.html(''); + const $alert = $("#alert-box") + $alert.html('') if (typeof response.responseJSON.error === 'string' || response.responseJSON.error instanceof String) { $alert.html(` @@ -47,18 +47,18 @@ function error_response(response) { ${response.responseJSON.error} - `); + `) } else if (response.responseJSON.error instanceof Array) { var output = '' - for (var i = 0; i < response.responseJSON.error.length; i ++) { + for (let i = 0; i < response.responseJSON.error.length; i ++) { output += ` - `; - $alert.html(output); + ` + $alert.html(output) } } } @@ -74,13 +74,13 @@ $('#dismiss-cookie-alert').click(function(event){ }, dataType: 'json', success: function(response){ - console.log(response); + console.log(response) }, error: function(response){ - console.log(response); + console.log(response) } }) - event.preventDefault(); + event.preventDefault() }) \ No newline at end of file diff --git a/ref-test/app/root/js/script.js b/ref-test/app/root/js/script.js index ba30892..0dfdf97 100644 --- a/ref-test/app/root/js/script.js +++ b/ref-test/app/root/js/script.js @@ -1,21 +1,21 @@ $(document).ready(function() { $("#od-font-test").click(function(){ $("body").css("font-family", "opendyslexic3regular") - }); + }) $('.test-code-input').keyup(function() { - var input = $(this).val().split("-").join("").split("—").join(""); + var input = $(this).val().split("-").join("").split("—").join("") if (input.length > 0) { - input = input.match(new RegExp('.{1,4}', 'g')).join("—"); + input = input.match(new RegExp('.{1,4}', 'g')).join("—") } - $(this).val(input); - }); -}); + $(this).val(input) + }) +}) $('form[name=form-quiz-start]').submit(function(event) { - var $form = $(this); - var data = $form.serialize(); + var $form = $(this) + var data = $form.serialize() $.ajax({ url: window.location.pathname, @@ -24,21 +24,21 @@ $('form[name=form-quiz-start]').submit(function(event) { dataType: 'json', success: function(response) { var id = response.id - window.localStorage.setItem('id', id); - window.location.href = `/quiz/`; + window.localStorage.setItem('id', id) + window.location.href = `/quiz/` }, error: function(response) { - error_response(response); + error_response(response) } - }); + }) - event.preventDefault(); -}); + event.preventDefault() +}) function error_response(response) { - const $alert = $("#alert-box"); - $alert.html(''); + const $alert = $("#alert-box") + $alert.html('') if (typeof response.responseJSON.error === 'string' || response.responseJSON.error instanceof String) { $alert.html(` @@ -47,18 +47,18 @@ function error_response(response) { ${response.responseJSON.error} - `); + `) } else if (response.responseJSON.error instanceof Array) { var output = '' - for (var i = 0; i < response.responseJSON.error.length; i ++) { + for (let i = 0; i < response.responseJSON.error.length; i ++) { output += ` - `; - $alert.html(output); + ` + $alert.html(output) } } } @@ -74,13 +74,13 @@ $('#dismiss-cookie-alert').click(function(event){ }, dataType: 'json', success: function(response){ - console.log(response); + console.log(response) }, error: function(response){ - console.log(response); + console.log(response) } }) - event.preventDefault(); + event.preventDefault() }) \ No newline at end of file