Javascript Quiz

Содержание
  1. Create a Quiz App with Timer using HTML CSS & JavaScript
  2. You might like this:
  3. Create a Quiz App using HTML CSS & JavaScript
  4. Full Video Tutorial of Background Image Slider
  5. Create a Quiz App using HTML CSS & JavaScript [Source Codes]
  6. # HTML CODE
  7. # CSS CODE
  8. # JS CODE
  9. You answered $/$ questions correctly
  10. Quiz Website Using HTML, CSS & JavaScript (Source Code)
  11. Video Tutorial Of Quiz App Using Javascript
  12. HTML Code For Quiz App
  13. 1.
  14. CSS Code For Quiz App
  15. Javascript Code For Quiz App
  16. Total Score:  " + scr + '/' + totalque + ""); for (var j = 0; j < totalque; j++) < var res; if (quiz.JS[j].score == 0) < res = '' + quiz.JS[j].score + ' '; > else < res = '' + quiz.JS[j].score + ' '; > $("#result").append( 'Q ' + quiz.JS[j].id + '  ' + quiz.JS[j].question + '' + 'Correct answer:  ' + quiz.JS[j].answer + '' + 'Score:  ' + res + '' ); > > this.checkAnswer = function (option) < var answer = quiz.JS[this.currentque].answer; option = option.replace(//g, ">") //for > option = option.replace(/"/g, """) if (option == quiz.JS[this.currentque].answer) < if (quiz.JS[this.currentque].score == "") < quiz.JS[this.currentque].score = 1; quiz.JS[this.currentque].status = "correct"; >> else < quiz.JS[this.currentque].status = "wrong"; >> this.changeQuestion = function (cque) < this.currentque = this.currentque + cque; this.displayQuiz(this.currentque); >> var jsq = new quizApp(); var selectedopt; $(document).ready(function () < jsq.displayQuiz(0); $('#question-options').on('change', 'input[type=radio][name=option]', function (e) < //var radio = $(this).find('input:radio'); $(this).prop("checked", true); selectedopt = $(this).val(); >); >); $('#next').click(function (e) < e.preventDefault(); if (selectedopt) < jsq.checkAnswer(selectedopt); >jsq.changeQuestion(1); >); $('#previous').click(function (e) < e.preventDefault(); if (selectedopt) < jsq.checkAnswer(selectedopt); >jsq.changeQuestion(-1); >); First, we built an object in our Javascript, and then we added a question with a certain ID number to that object. We have built 25 questions in total and placed them within our object. The user will receive the quiz task’s outcome at the end of the quiz by utilizing the conditional statements to verify, as the user clicks on any of the alternatives, if and else statements, whether the answer they choose matches the proper response. Final output For Quiz App Now that we have completed our javascript section Quiz App. our updated output with Html, CSS, and Javascript For Quiz App. Источник
  17. Final output For Quiz App

Create a Quiz App with Timer using HTML CSS & JavaScript

Hello readers, Today in this blog you’ll learn how to Create a Quiz Application with Timer using HTML CSS & JavaScript. Earlier I’ve shared a blog on how to Create a Responsive Personal Portfolio Website and now it’s time to create Quiz Web App using JavaScript. In this program [Quiz App with Timer], there are three layers or boxes, and these boxes shown one by one on a particular button clicked. At first, on the webpage, there is shown a button labeled as «Start Quiz» and when you clicked on that button, then the info box appears with popup animation. In this infobox, there are some rules of the quiz and two buttons labeled as «Exit» and «Continue». When you clicked on the Exit button, the info box will be hidden but when you clicked on the Continue button, then the Quiz Box appears. In the Quiz Box, there is a header with a title on the left side and a timer box on the right side. This timer starts decrement from 15 to 0 sec and there is also shown a timeline indicator that is sliding from the left to right side according to the timer. If the user selects an option between 15 to 0 sec, the timer will be stopped and all available options will be disabled. If the user selected option is correct, the selected option color, background color changed to green and there is also shown the tick icon to inform the user that the selected answer is correct. If the user selects an option that is incorrect, the selected option color, background-color changed to red and there is shown the cross icon to inform the user that the selected option is incorrect and the correct option will be automatically selected. If the user doesn’t select an option between 15 to 0 sec, the timer will be stopped once it comes in 0 and the correct option of that question will be selected automatically. After that, there is the next button to show the next question, and there is a total of five questions on this Quiz. In the end, the result box will be appeared and shown the user score and two buttons [Replay Quiz, Quit Quiz], if the user clicked on the replay quiz button, the quiz will again start with the number 1 question, and the score of the user will be 0 but if the user clicked on the quit quiz button, the current window will be reloaded and the quiz starts from the begin. You can copy the codes from the given boxes or download the code files from the given link but I recommend you to download the source code files instead of copying codes. Click here to download code files.

Читайте также:  Java static блок инициализации

You might like this:

HTML CODE:
       Awesome Quiz App | CodingNepal -->     
Some Rules of this Quiz
1. You will have only 15 seconds per each question.
2. Once you select your answer, it can't be undone.
3. You can't select any option once time goes off.
4. You can't exit from the Quiz while you're playing.
5. You'll get points on the basis of your correct answers.
Awesome Quiz Application
Time Left
15
You've completed the Quiz!
--> -->
CSS CODE:
/* importing google fonts */ @import url('https://fonts.googleapis.com/css2?family=Poppins:wght@200;300;400;500;600;700&display=swap'); * < margin: 0; padding: 0; box-sizing: border-box; font-family: 'Poppins', sans-serif; >body < background: #007bff; >::selection < color: #fff; background: #007bff; >.start_btn, .info_box, .quiz_box, .result_box < position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19); >.info_box.activeInfo, .quiz_box.activeQuiz, .result_box.activeResult < opacity: 1; z-index: 5; pointer-events: auto; transform: translate(-50%, -50%) scale(1); >.start_btn button < font-size: 25px; font-weight: 500; color: #007bff; padding: 15px 30px; outline: none; border: none; border-radius: 5px; background: #fff; cursor: pointer; >.info_box < width: 540px; background: #fff; border-radius: 5px; transform: translate(-50%, -50%) scale(0.9); opacity: 0; pointer-events: none; transition: all 0.3s ease; >.info_box .info-title < height: 60px; width: 100%; border-bottom: 1px solid lightgrey; display: flex; align-items: center; padding: 0 30px; border-radius: 5px 5px 0 0; font-size: 20px; font-weight: 600; >.info_box .info-list < padding: 15px 30px; >.info_box .info-list .info < margin: 5px 0; font-size: 17px; >.info_box .info-list .info span < font-weight: 600; color: #007bff; >.info_box .buttons < height: 60px; display: flex; align-items: center; justify-content: flex-end; padding: 0 30px; border-top: 1px solid lightgrey; >.info_box .buttons button < margin: 0 5px; height: 40px; width: 100px; font-size: 16px; font-weight: 500; cursor: pointer; border: none; outline: none; border-radius: 5px; border: 1px solid #007bff; transition: all 0.3s ease; >.quiz_box < width: 550px; background: #fff; border-radius: 5px; transform: translate(-50%, -50%) scale(0.9); opacity: 0; pointer-events: none; transition: all 0.3s ease; >.quiz_box header < position: relative; z-index: 2; height: 70px; padding: 0 30px; background: #fff; border-radius: 5px 5px 0 0; display: flex; align-items: center; justify-content: space-between; box-shadow: 0px 3px 5px 1px rgba(0,0,0,0.1); >.quiz_box header .title < font-size: 20px; font-weight: 600; >.quiz_box header .timer < color: #004085; background: #cce5ff; border: 1px solid #b8daff; height: 45px; padding: 0 8px; border-radius: 5px; display: flex; align-items: center; justify-content: space-between; width: 145px; >.quiz_box header .timer .time_left_txt < font-weight: 400; font-size: 17px; user-select: none; >.quiz_box header .timer .timer_sec < font-size: 18px; font-weight: 500; height: 30px; width: 45px; color: #fff; border-radius: 5px; line-height: 30px; text-align: center; background: #343a40; border: 1px solid #343a40; user-select: none; >.quiz_box header .time_line < position: absolute; bottom: 0px; left: 0px; height: 3px; background: #007bff; >section < padding: 25px 30px 20px 30px; background: #fff; >section .que_text < font-size: 25px; font-weight: 600; >section .option_list < padding: 20px 0px; display: block; >section .option_list .option < background: aliceblue; border: 1px solid #84c5fe; border-radius: 5px; padding: 8px 15px; font-size: 17px; margin-bottom: 15px; cursor: pointer; transition: all 0.3s ease; display: flex; align-items: center; justify-content: space-between; >section .option_list .option:last-child < margin-bottom: 0px; >section .option_list .option:hover < color: #004085; background: #cce5ff; border: 1px solid #b8daff; >section .option_list .option.correct < color: #155724; background: #d4edda; border: 1px solid #c3e6cb; >section .option_list .option.incorrect < color: #721c24; background: #f8d7da; border: 1px solid #f5c6cb; >section .option_list .option.disabled < pointer-events: none; >section .option_list .option .icon < height: 26px; width: 26px; border: 2px solid transparent; border-radius: 50%; text-align: center; font-size: 13px; pointer-events: none; transition: all 0.3s ease; line-height: 24px; >.option_list .option .icon.tick < color: #23903c; border-color: #23903c; background: #d4edda; >.option_list .option .icon.cross < color: #a42834; background: #f8d7da; border-color: #a42834; >footer < height: 60px; padding: 0 30px; display: flex; align-items: center; justify-content: space-between; border-top: 1px solid lightgrey; >footer .total_que span < display: flex; user-select: none; >footer .total_que span p < font-weight: 500; padding: 0 5px; >footer .total_que span p:first-child < padding-left: 0px; >footer button < height: 40px; padding: 0 13px; font-size: 18px; font-weight: 400; cursor: pointer; border: none; outline: none; color: #fff; border-radius: 5px; background: #007bff; border: 1px solid #007bff; line-height: 10px; opacity: 0; pointer-events: none; transform: scale(0.95); transition: all 0.3s ease; >footer button:hover < background: #0263ca; >footer button.show < opacity: 1; pointer-events: auto; transform: scale(1); >.result_box < background: #fff; border-radius: 5px; display: flex; padding: 25px 30px; width: 450px; align-items: center; flex-direction: column; justify-content: center; transform: translate(-50%, -50%) scale(0.9); opacity: 0; pointer-events: none; transition: all 0.3s ease; >.result_box .icon < font-size: 100px; color: #007bff; margin-bottom: 10px; >.result_box .complete_text < font-size: 20px; font-weight: 500; >.result_box .score_text span < display: flex; margin: 10px 0; font-size: 18px; font-weight: 500; >.result_box .score_text span p < padding: 0 4px; font-weight: 600; >.result_box .buttons < display: flex; margin: 20px 0; >.result_box .buttons button < margin: 0 10px; height: 45px; padding: 0 20px; font-size: 18px; font-weight: 500; cursor: pointer; border: none; outline: none; border-radius: 5px; border: 1px solid #007bff; transition: all 0.3s ease; >.buttons button.restart < color: #fff; background: #007bff; >.buttons button.restart:hover < background: #0263ca; >.buttons button.quit < color: #007bff; background: #fff; >.buttons button.quit:hover

Источник

Create a Quiz App using HTML CSS & JavaScript

create a quiz app using html css javascript

Hello , Today in this blog you’ll learn How to Create a Quiz App using HTML CSS & JavaScript . Earlier I have shared a blog on Background Image Slider Using Html Css & javascript and now it’s time to Create a Quiz App.

If you are familiar with HTML CSS & JAVASCRIPT then you can easily create this Create a Quiz App using HTML CSS & JavaScript . Those People who are feeling difficult to understand this, don’t worry You can watch a full video tutorial on this Quiz App .

Full Video Tutorial of Background Image Slider

Create a Quiz App using HTML CSS & JavaScript [Source Codes]

To create this Quiz App First, you need to create Three files, HTML File CSS File And JAVASCRIPT File. After creating these files Just copy the given source code and paste into your text editor and edit it according to your requirement. You can also download the source code files of this Quiz App using HTML CSS & JavaScript from the given download button.

# HTML CODE

First, create a Html file (index.html) and paste the given codes in your CSS file.

# CSS CODE

Second, you create an CSS file (style.css) and paste the given codes in your CSS file.

/* coding with nick */ @import url(‘https://fonts.googleapis.com/css2?family=Poppins:wght@200;300;400;500&display=swap’); * < box-sizing: border-box; >body < background-color: #b8c6db; background-image: linear-gradient(315deg, #b8c6db 0%, #f5f7f7 100%); font-family: 'Poppins', sans-serif; display: flex; align-items: center; justify-content: center; height: 100vh; overflow: hidden; margin: 0; >.quiz-container < background-color: #fff; border-radius: 10px; box-shadow: 0 0 10px 2px rgba(100, 100, 100, 0.1); width: 600px; overflow: hidden; >.quiz-header < padding: 4rem; >h2 < padding: 1rem; text-align: center; margin: 0; >ul < list-style-type: none; padding: 0; >ul li < font-size: 1.2rem; margin: 1rem 0; >ul li label < cursor: pointer; >button < background-color: #03cae4; color: #fff; border: none; display: block; width: 100%; cursor: pointer; font-size: 1.1rem; font-family: inherit; padding: 1.3rem; >button:hover < background-color: #04adc4; >button:focus

# JS CODE

Last, create a JavaScript file ( script.js ) and paste the given codes in your JavaScript file.

const quizData = [ < question: "Which language runs in a web browser?", a: "Java", b: "C", c: "Python", d: "javascript", correct: "d", >, < question: "What does CSS stand for?", a: "Central Style Sheets", b: "Cascading Style Sheets", c: "Cascading Simple Sheets", d: "Cars SUVs Sailboats", correct: "b", >, < question: "What does HTML stand for?", a: "Hypertext Markup Language", b: "Hypertext Markdown Language", c: "Hyperloop Machine Language", d: "Helicopters Terminals Motorboats Lamborginis", correct: "a", >, < question: "What year was JavaScript launched?", a: "1996", b: "1995", c: "1994", d: "none of the above", correct: "b", >, ]; const quiz= document.getElementById('quiz') const answerEls = document.querySelectorAll('.answer') const questionEl = document.getElementById('question') const a_text = document.getElementById('a_text') const b_text = document.getElementById('b_text') const c_text = document.getElementById('c_text') const d_text = document.getElementById('d_text') const submitBtn = document.getElementById('submit') let currentQuiz = 0 let score = 0 loadQuiz() function loadQuiz() < deselectAnswers() const currentQuizData = quizData[currentQuiz] questionEl.innerText = currentQuizData.question a_text.innerText = currentQuizData.a b_text.innerText = currentQuizData.b c_text.innerText = currentQuizData.c d_text.innerText = currentQuizData.d >function deselectAnswers() < answerEls.forEach(answerEl =>answerEl.checked = false) > function getSelected() < let answer answerEls.forEach(answerEl => < if(answerEl.checked) < answer = answerEl.id >>) return answer > submitBtn.addEventListener('click', () => < const answer = getSelected() if(answer) < if(answer === quizData[currentQuiz].correct) < score++ >currentQuiz++ if(currentQuiz < quizData.length) < loadQuiz() >else < quiz.innerHTML = ` 

You answered $/$ questions correctly

` > > >)

That’s all, now you’ve successfull Quiz App using HTML CSS & JavaScript . If your code doesn’t work or you’ve faced any error And problem’s , please download the source code from the given download button.

I Hope this blog will be helpful.

Источник

Quiz Website Using HTML, CSS & JavaScript (Source Code)

Welcome to the CodeWithRandom blog. In this article, We create a Quiz Website using HTML, CSS, And JavaScript. We give you the Complete source code of the Quiz Website.

Quiz Website Using HTML, CSS & JavaScript (Source Code)

The main purpose of making a quiz app is to make javascript concepts clearer and give users access to a web app so they may practice for competitive exams and improve their general knowledge. We’ll build a quiz app in this article.

master frontend development ebook cover

Do you want to learn HTML to JavaScript? 🔥

If yes, then here is our Master Frontend: Zero to Hero eBook! 📚 In this eBook, you’ll learn complete HTML, CSS, Bootstrap, and JavaScript from beginner to advance level. 💪 It includes 450 Projects with source code.

Video Tutorial Of Quiz App Using Javascript

I hope you enjoy this video tutorial so let’s start with a basic HTML structure for the Quiz App Using Javascript.

HTML Code For Quiz App

           
JS Quiz
Total Questions:

1.

 

HTML Structure :

We’ll add a few links to the external javascript and CSS files inside the header section before adding structure to our website. Additionally, since we utilised Bootstrap for this project, we need to include certain Bootstrap links in it.

Before continuing, If you want to learn complete frontend web development then we have launched an E-Book “Master Frontend Development: Zero to Hero” for you. This E-Book includes hand-crafted lessons on HTML, CSS, Javascript, and Bootstrap. And also 100+ frontend projects and interview questions as well.

  • Now using the div tag we will add the container of our quiz app .
  • Using the div tag we will add two title one is for javascript quiz and another is for counting the total number of question inside our quiz app.
  • After that, we will add the structure of a form, such as one with a question, using the bootstrap predefined classes, and we will add the 4 alternatives to each question using the radio type input.
  • Next, we will construct two buttons with the button tag: one for going to the previous question and one for the following question.

Html output for quiz app

Create Quiz App Using Html,Css And Javascript (Source Code)

CSS Code For Quiz App

.content < margin-top: 54px; >.header < padding: 15px; position: fixed; top: 0; width: 100%; z-index: 9999; >.left-title < width: 80px; color: #fff; font-size: 18px; float: left; >.right-title < width: 150px; text-align: right; float: right; color: #fff; >.quiz-body < margin-top: 15px; padding-bottom: 50px; >.option-block-container < margin-top: 20px; max-width: 420px; >.option-block < padding: 10px; background: aliceblue; border: 1px solid #84c5fe; margin-bottom: 10px; cursor: pointer; >.result-question < font-weight: bold; >.c-wrong < margin-left: 20px; color: #ff0000; >.c-correct < margin-left: 20px; color: green; >.last-row < border-bottom: 1px solid #ccc; padding-bottom: 25px; margin-bottom: 25px; >.res-header

However, some of the default stylings is derived from the bootstrap predefined CSS. We have just contributed a few extra stylings to our quiz app’s CSS. The individual elements of our quiz app will get extra padding and margin in our css file using the class selector, making it seem more likable.

Updated output With Html And CSS code For Quiz App

Create Quiz App Using Html,Css And Javascript (Source Code)

Javascript Code For Quiz App

/* Created and coded by Abhilash Narayan */ /* Quiz source: w3schools.com */ var quiz = < "JS": [ < "id": 1, "question": "Inside which HTML element do we put the JavaScript?", "options": [ < "a": "<script>", "b": "<javascript>", "c": "<scripting>", "d": "<js>" >], "answer": "<script>", "score": 0, "status": "" >, < "id": 2, "question": "Where is the correct place to insert a JavaScript?", "options": [ < "a": "The <head> section", "b": "The <body> section", "c": "Both the <head> section and the <body> section are correct" >], "answer": "Both the <head> section and the <body> section are correct", "score": 0, "status": "" >, < "id": 3, "question": "What is the correct syntax for referring to an external script called 'xxx.js'?", "options": [ < "a": "&ltscript href="xxx.js">", "b": "<script name="xxx.js">", "c": "<script src="xxx.js">" > ], "answer": "<script src="xxx.js">", "score": 0, "status": "" >, < "id": 4, "question": "The external JavaScript file must contain the <script> tag.", "options": [ < "a": "True", "b": "False" >], "answer": "False", "score": 0, "status": "" >, < "id": 5, "question": "How do you write "Hello World" in an alert box?", "options": [ < "a": "alertBox("Hello World");", "b": "msg("Hello World");", "c": "alert("Hello World");", "d": "msgBox("Hello World");", >], "answer": "alert("Hello World");", "score": 0, "status": "" >, < "id": 6, "question": "How do you create a function in JavaScript?", "options": [ < "a": "function myFunction()", "b": "function:myFunction()", "c": "function = myFunction()", >], "answer": "function myFunction()", "score": 0, "status": "" >, < "id": 7, "question": "How do you call a function named "myFunction"?", "options": [ < "a": "call function myFunction()", "b": "call myFunction()", "c": "myFunction()", >], "answer": "myFunction()", "score": 0, "status": "" >, < "id": 8, "question": "How to write an IF statement in JavaScript?", "options": [ < "a": "if i = 5 then", "b": "if i == 5 then", "c": "if (i == 5)", "d": " if i = 5", >], "answer": "if (i == 5)", "score": 0, "status": "" >, < "id": 9, "question": "Which of the following is a disadvantage of using JavaScript?", "options": [ < "a": "Client-side JavaScript does not allow the reading or writing of files.", "b": "JavaScript can not be used for Networking applications because there is no such support available.", "c": "JavaScript doesn't have any multithreading or multiprocess capabilities.", "d": "All of the above." >], "answer": "All of the above.", "score": 0, "status": "" >, < "id": 10, "question": "How to write an IF statement for executing some code if "i" is NOT equal to 5?", "options": [ < "a": "if (i <>5)", "b": "if i <> 5", "c": "if (i != 5)", "d": "if i =! 5 then", > ], "answer": "if (i != 5)", "score": 0, "status": "" >, < "id": 11, "question": "How does a WHILE loop start?", "options": [ < "a": "while i = 1 to 10", "b": "while (i <= 10; i++)", "c": "while (i <= 10)" >], "answer": "while (i <= 10)", "score": 0, "status": "" >, < "id": 12, "question": "How does a FOR loop start?", "options": [ < "a": "for (i = 0; i <= 5)", "b": "for (i = 0; i <= 5; i++)", "c": "for i = 1 to 5", "d": "for (i <= 5; i++)" >], "answer": "for (i = 0; i <= 5; i++)", "score": 0, "status": "" >, < "id": 13, "question": "How can you add a comment in a JavaScript?", "options": [ < "a": "//This is a comment", "b": "‚This is a comment", "c": "<!--This is a comment-->" >], "answer": "//This is a comment", "score": 0, "status": "" >, < "id": 14, "question": "How to insert a comment that has more than one line?", "options": [ < "a": "/*This comment has more than one line*/", "b": "//This comment has more than one line//", "c": "<!--This comment has more than one line-->" >], "answer": "/*This comment has more than one line*/", "score": 0, "status": "" >, < "id": 15, "question": "What is the correct way to write a JavaScript array?", "options": [ < "a": "var colors = (1:"red", 2:"green", 3:"blue")", "b": "var colors = ["red", "green", "blue"]", "c": "var colors = 1 = ("red"), 2 = ("green"), 3 = ("blue")", "d": "var colors = "red", "green", "blue"" >], "answer": "var colors = ["red", "green", "blue"]", "score": 0, "status": "" >, < "id": 16, "question": "How do you round the number 7.25, to the nearest integer?", "options": [ < "a": "rnd(7.25)", "b": "Math.round(7.25)", "c": "Math.rnd(7.25)", "d": "round(7.25)" >], "answer": "Math.round(7.25)", "score": 0, "status": "" >, < "id": 17, "question": "How do you find the number with the highest value of x and y?", "options": [ < "a": "Math.max(x, y)", "b": "Math.ceil(x, y)", "c": "top(x, y)", "d": "ceil(x, y)" >], "answer": "Math.max(x, y)", "score": 0, "status": "" >, < "id": 18, "question": "What is the correct JavaScript syntax for opening a new window called "w2"?", "options": [ < "a": "w2 = window.new("http://www.w3schools.com");", "b": "w2 = window.open("http://www.w3schools.com");" >], "answer": "w2 = window.open("http://www.w3schools.com");", "score": 0, "status": "" >, < "id": 19, "question": "JavaScript is the same as Java.", "options": [ < "a": "true", "b": "false" >], "answer": "false", "score": 0, "status": "" >, < "id": 20, "question": "How can you detect the client’s browser name?", "options": [ < "a": "navigator.appName", "b": "browser.name", "c": "client.navName" >], "answer": "navigator.appName", "score": 0, "status": "" >, < "id": 21, "question": "Which event occurs when the user clicks on an HTML element?", "options": [ < "a": "onchange", "b": "onclick", "c": "onmouseclick", "d": "onmouseover" >], "answer": "onclick", "score": 0, "status": "" >, < "id": 22, "question": "How do you declare a JavaScript variable?", "options": [ < "a": "var carName;", "b": "variable carName;", "c": "v carName;" >], "answer": "var carName;", "score": 0, "status": "" >, < "id": 23, "question": "Which operator is used to assign a value to a variable?", "options": [ < "a": "*", "b": "-", "c": "=", "d": "x" >], "answer": "=", "score": 0, "status": "" >, < "id": 24, "question": "What will the following code return: Boolean(10 > 9)", "options": [ < "a": "NaN", "b": "false", "c": "true" >], "answer": "true", "score": 0, "status": "" >, < "id": 25, "question": "Is JavaScript case-sensitive?", "options": [ < "a": "No", "b": "Yes" >], "answer": "Yes", "score": 0, "status": "" > ] > var quizApp = function () < this.score = 0; this.qno = 1; this.currentque = 0; var totalque = quiz.JS.length; this.displayQuiz = function (cque) < this.currentque = cque; if (this.currentque < totalque) < $("#tque").html(totalque); $("#previous").attr("disabled", false); $("#next").attr("disabled", false); $("#qid").html(quiz.JS[this.currentque].id + '.'); $("#question").html(quiz.JS[this.currentque].question); $("#question-options").html(""); for (var key in quiz.JS[this.currentque].options[0]) < if (quiz.JS[this.currentque].options[0].hasOwnProperty(key)) < $("#question-options").append( "
" + "" ); > > > if (this.currentque if (this.currentque >= totalque) < $('#next').attr('disabled', true); for (var i = 0; i < totalque; i++) < this.score = this.score + quiz.JS[i].score; >return this.showResult(this.score); > > this.showResult = function (scr) < $("#result").addClass('result'); $("#result").html("

Total Score:  " + scr + '/' + totalque + "

"); for (var j = 0; j < totalque; j++) < var res; if (quiz.JS[j].score == 0) < res = '' + quiz.JS[j].score + ' '; > else < res = '' + quiz.JS[j].score + ' '; > $("#result").append( '
Q ' + quiz.JS[j].id + '  ' + quiz.JS[j].question + '
' + '
Correct answer:  ' + quiz.JS[j].answer + '
' + '
Score:  ' + res + '
' ); > > this.checkAnswer = function (option) < var answer = quiz.JS[this.currentque].answer; option = option.replace(//g, ">") //for > option = option.replace(/"/g, """) if (option == quiz.JS[this.currentque].answer) < if (quiz.JS[this.currentque].score == "") < quiz.JS[this.currentque].score = 1; quiz.JS[this.currentque].status = "correct"; >> else < quiz.JS[this.currentque].status = "wrong"; >> this.changeQuestion = function (cque) < this.currentque = this.currentque + cque; this.displayQuiz(this.currentque); >> var jsq = new quizApp(); var selectedopt; $(document).ready(function () < jsq.displayQuiz(0); $('#question-options').on('change', 'input[type=radio][name=option]', function (e) < //var radio = $(this).find('input:radio'); $(this).prop("checked", true); selectedopt = $(this).val(); >); >); $('#next').click(function (e) < e.preventDefault(); if (selectedopt) < jsq.checkAnswer(selectedopt); >jsq.changeQuestion(1); >); $('#previous').click(function (e) < e.preventDefault(); if (selectedopt) < jsq.checkAnswer(selectedopt); >jsq.changeQuestion(-1); >);

First, we built an object in our Javascript, and then we added a question with a certain ID number to that object. We have built 25 questions in total and placed them within our object. The user will receive the quiz task’s outcome at the end of the quiz by utilizing the conditional statements to verify, as the user clicks on any of the alternatives, if and else statements, whether the answer they choose matches the proper response.

Final output For Quiz App

Create Quiz App Using Html,Css And Javascript (Source Code)

Create Quiz App Using Html,Css And Javascript (Source Code)

Now that we have completed our javascript section Quiz App. our updated output with Html, CSS, and Javascript For Quiz App.

Источник

Оцените статью