Determine the outcome of the assessment quiz

Greetings everyone, I apologize for my poor English. I've been searching through numerous documents, but due to my language barrier, I am having trouble understanding them. I have designed a quiz page, but I'm facing an issue where I can't display the results at the end of the page.

Here's what I want:

  1. If the user selects the true section, they should receive a success message. If they select the false section, they should receive an error message (I've achieved this).
  2. The page needs to show how many correct answers were selected (I'm struggling with the algorithm for this).

I've made attempts, but unfortunately, there are several mistakes in my code. Can anyone assist me in determining how many questions have been correctly answered?

This is my HTML Code:

<html>
    <head>  
        <link href="css/boostrap.css" rel="stylesheet" media="screen">  
        <link href="css/deneme.css" rel="stylesheet" media="screen">
        <link href="css/style.css" rel="stylesheet" media="screen"> 
        <script type="text/JavaScript" src="scripts/jquery.alerts.js"></script>
        <script type="text/JavaScript" src="scripts/jquery-1.8.2.js"></script>
        <script type="text/JavaScript" src="scripts/jquery.js"></script>


        <script  type="text/JavaScript" >
            // if they click false section it gives error message
            $(".alerts").on('click', function() {
                var did = $(this).attr('data-id');
                $(document).trigger("set-alert-id-" + did, [
                    {
                        'message': "Wrong",
                        'priority': 'warning'
                    }]);
            });

            // if they click true section it gives success message
            $(".alerts-success").on('click', function() {
                var did = $(this).attr('data-id');
                $(document).trigger("set-alert-id-" + did, [
                    {
                        'message': "Success",
                        'priority': 'warning'
                    }]);
            });

            // I try something to show how many question is true selected but I can not      do this
            function askQuestion(question) {
                var answer = prompt(question[0], '');
                if (answer == question[1]) {
                    alert('Correct!');
                    score++;
                } else {
                    alert('Sorry. The correct answer is ' + question[1]);
                }
            }

            var message = 'You got ' + score;
            message += ' out of ' + questions.length;
            message += ' questions correct.';
            document.write('<p>' + message + '</p>');
        </script>
    </head>

...

CSS CODE:

.quiz_container {
    list-style-type: none !important;
    font-weight: bold;
    color: #21252E;
    width: 98%;
}

/*fluid grid layout using twitter bootstrap */

.row-fluid {
    margin-left: 0 !important;
}

...

@media (max-width: 480px) {
    .quiz_container li {
        font-size: 1em !important;
    }

    .quiz_container .question_container h1 {
        font-family: verdana, sans-serif;
        font-size: 1.25em;
    }

    .quiz_container .question img, .revealed_answer img {
        display: none;
    }

    .quiz_container .question_container {
        margin: 1em 0em 3.5em;
    }
}

Answer №1

Feel free to review my code on http://jsfiddle.net/LaB92/1/

I have removed the CSS and Bootstrap, so you can add your own styling to make it visually appealing

Now, onto the solution

  • Each question is enclosed within "LI - .single_question"

    <li class="single_question">

  • The correct answer for each question is stored as an attribute in the .single_question element -

    <li class="single_question" data-correct-answer="OPTION VALUE"></li>

  • data-question-id is an additional attribute that I didn't utilize, but you may find a use for it later on

  • Place your options inside

    <ul class="options"></ul>

  • Remember to assign values to the li elements -

    <li value="OPTION VALUE"> SOME OPTION TEXT </li>

  • The individual result is automatically displayed in

    <div class="result"></div>
    . This should be included for every question

  • Whenever an option is selected, the score_calculator() function is invoked to calculate the score

If you need further clarification on the code or want to enhance its functionality, feel free to ask. I've provided a basic structure here..

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Exploring Django's view field for efficient data rendering

Is it possible to display multiple views for a single page/template? For instance, imagine a website where users can submit movie reviews and read others' reviews as well. Now, I need to add an edit button to the review pages but only want the button ...

What is the best way to transfer Flow type properties from one React component to another?

I'm in the process of developing a component that will wrap another component known as Button. The tricky part is that the library where Button is defined does not expose the type of its properties. In order to properly assign types to my component, ...

The image in the footer seems to have a mind of its own, refusing to stay put and instead choosing to wander

Is it possible to add a small icon at the bottom of the footer that scrolls up or down as I scroll, instead of remaining fixed? I'm unsure if the issue lies in setting the image as sticky on scroll or if it's a CSS error. I attempted to set the ...

The login page allows entry of any password

I'm running a xamp-based webserver with an attendance system installed. I have 10 registered users who are supposed to log in individually to enter their attendance. However, there seems to be an issue on the login page where any password is accepted ...

Unlocking the potential of the ‘Rx Observable’ in Angular 2 to effectively tackle double click issues

let button = document.querySelector('.mbtn'); let lab = document.querySelector('.mlab'); let clickStream = Observable.fromEvent(button,'click'); let doubleClickStream = clickStream .buffer(()=> clickStream.thrott ...

Transform a single data point into pixels by converting its latitude and longitude coordinates

I am facing a specific challenge where I have hit a roadblock after conducting some research. The issue at hand is this: I am working with a raster image that has known dimensions (800 x 800 px) I have two points within this image with their pixel and g ...

Utilizing space with margin and padding in Bootstrap 5

I recently started experimenting with bootstrap 5, but I'm feeling quite disoriented. The layout I have created includes some blue elements (borrowed the sidebar from this source) and now I am attempting to replicate this design. https://i.sstatic.ne ...

What is the process for accessing an uploaded file in a server-side Classic ASP page?

I'm attempting to use Ajax to upload a file to a server-side script in classic ASP. Here is the relevant HTML and JavaScript code: <input type="file" id="fileInput" /> and function saveToServer(file) { const fd = new FormData(); fd.a ...

Performing Jquery functions on several elements at once

Looking at the code snippet below, there are two buttons and an input in each container. The input calculates and adds up the number of clicks on the 2 buttons within the same container. However, it currently only works for the first container. How can thi ...

Transform jQuery code to its equivalent in vanilla JavaScript

While I am proficient in using jQuery, my knowledge of pure JavaScript is somewhat limited. Below is the jQuery code that I have been working with: $(document).ready(function() { $.get('http://jsonip.com/', function(r){ var ip_addre ...

The website functions properly in Chrome, but encounters issues in IE

Currently working on validating some JavaScript code. Chrome seems to be handling it well, but as expected, IE is causing some issues. Take a look at the code below: function validateData(a,id){ var inputs = document.getElementsByName('attname[] ...

Displaying JSON data using Vue.js

fetching JSON data save movieData: {} ...... retrieveMovieData (context, parameter) { axios.get(API.movieData + parameter.id) .then(response => { context.commit('MOVIE_DATA', response.data) }) .catch(error => ...

Creating a unique Tag Name for Dynamic Components in Angular

I want to customize a component @Component({ selector: '[my-component]', template: `<i>1</i><p>content</p><b>2</b>` }) export class MyComponent { public tagName: string; } Then there's another comp ...

Using AJAX to submit data and displaying the results in either an input field or a div

Having a PHP script to track button clicks to a text file <?php if (isset($_POST['clicks1'])) { incrementClickCount1(); } function getClickCount1() { return (int) file_get_contents("count_files/clickcount1.txt"); } function increme ...

No traces of SOI could be detected in the stored canvas image

I have a unique project using Three.js, where I am enabling users to save diagrams they draw on a canvas as JPEG images. The process involves: <a id="download" download="PathPlanner.jpg">Download as image</a> function download() { var dt = ca ...

Tips for shifting an image upwards and extending it beyond one section while keeping the other section unaffected

Struggling all day while designing a CSS site, trying to hide one part of an image when it overflows and keep another part visible, in addition to moving the image up and down. Here's the HTML code snippet: <section class="next-gen"&g ...

I attempted to implement a login feature using a prompt within a React application, but I encountered a situation where the browser asked me for the same details twice. How can I resolve

https://i.sstatic.net/nhuC1.png I've been working on adding a login feature to my webpage where the content is only rendered if users input valid credentials. However, I've encountered a problem where the browser prompts for credentials twice in ...

What are the advantages of choosing express.js over Ruby on Sinatra?

Currently brainstorming for a social app and contemplating the switch from my initial option, Sinatra/Ruby to express.js/nodejs. My main focus is on the abundance of open source projects in Ruby that can expedite development. Another major consideration i ...

On smaller device screens, the full-height sidebar and content area experience some disruption

How can I resolve the height issue with sidebar and content area on smaller devices, maintaining 100% height for both? I'm having trouble fixing it with the current code. I am aiming to create a fixed-width sidebar that expands to full width on small ...

The functionality of `config.assets.debug = true` fails to

I've encountered an issue with the configuration on development where config.assets.debug = true doesn't seem to work correctly. Instead of having multiple separate JavaScript and CSS file inclusions, I'm getting a consolidated one: <li ...