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

Troubleshooting a Next.js background image problem when hosting on Netlify

I've encountered an issue while attempting to deploy a nextjs website on Netlify. Everything works perfectly on my local server, but once it's on Netlify, the background image URL changes and the image becomes invisible. Original CSS code: backg ...

choose particular column in every row from the table's header class name

Every <th> in a table has a class, while the <td> elements do not. Is there a way to style all corresponding <td> elements with the same styles as their <th> counterparts using only plain css without any script? Furthermore, since ...

Interactive search tool for toggling visibility of elements

Hello everyone, this is my initial post on StackOverflow. Keeping my fingers crossed that it goes smoothly! <input type="Text" id="filterTextBox" placeholder="Filter by name"/> <script type="text/javascript" src="/resources/events.js"></scr ...

Attempting to access a variable from outside the function

I am looking to pass the index variable from mapping to the event change function in my code snippet below: {this.data && this.data.map((item, index) => ( <tr className="table-info" key={index}> <td>{index}</ ...

I'm currently working on incorporating an edit feature into the create form by utilizing server actions in the latest version of Next.js, version 14

The issue arises when the create form's type (id) parameter is null, which does not align with prisma's (edit info). export function AboutForm({ id }: { id: number }) { const router = useRouter(); const [err, setErr] = useState("&qu ...

Tracking in node.js to detect the creation of a new file

I'm currently working on a node.js script that requires immediate action upon the creation of a file with a specific name in a designated directory. While one way to achieve this could be through continuous calls to fs.readdir until the desired file i ...

Once you have successfully navigated past Div2, smoothly transition downwards to Div1 and transform it into a sticky

I wish to scroll down, and view #div1... also see #div2... When #div2 disappears from sight, I want #div1 to slide down and stay fixed at the top of the window. If I reach the footer div, I no longer want #div1 to remain sticky. If it's po ...

Using Single Quotes as Parameters in JavaScript

I'm currently facing an issue with a function that is designed to populate a field in the parent window when clicked. Specifically, it is meant to fill in a text field with a name. The challenge I am encountering arises when the field contains a sing ...

Checking for the existence of data in a MySQL table using Node.js resulted in an error message: "TypeError: res.send is

I am currently attempting to verify the existence of data in a mysql table. Upon doing so, I encountered an error indicating TypeError: res.send is not a function. The mysql table contains ample data with three columns, each specified as varchar(45), alon ...

ReactiveJS - Adding elements to an array and encountering the error of undefined

In two separate JavaScript files, I have 2 arrays declared as shown below: Index.JS: const [product, setProduct] = useState([]); const [item] = useState([ { name: 'Blue Dress', Image: '/static/media/Dress.1c414114.png', Pr ...

PHP Question: Why are variables within <?php ?> not accessible within if/else statements?

I'm currently working on a basic program that involves the user inputting a number, which is then processed to generate a series of random similar numbers. After this step, the program prompts the user to select the correct variable, which will be va ...

Update the style dynamically in Angular using an ngFor directive and an array of data

Is there a way to dynamically set the width using data from an array in Angular? The usual approach doesn't seem to work. How can I solve this issue? <div *ngFor="let item of products"> <div [style.width.px]="item.size" class="Holiday"&g ...

Center-aligned video text overlay that adapts to different screen sizes for a responsive design

I am looking to showcase a full-width video with overlay text that is perfectly centered both vertically and horizontally on the video. The centering should adapt to changes in viewport width so that it remains centered at all times. Additionally, I would ...

Animate failed due to the appending and adding of class

$('#clickMe').click(function() { $('#ticketsDemosss').append($('<li>').text('my li goes here')).addClass('fadeIn'); }); <link href="http://s.mlcdn.co/animate.css" rel="stylesheet"/> <script ...

Ways to center a div with position:relative vertically on the page

What is the best way to center a position relative div vertically within its parent element? For example: <div class="parent"> <div style="position:relative;" class="child"> </div> </div> Any suggestions on how to vertic ...

Steps to establish a maximum font size for my buttons

I've been working on creating buttons to decrease and increase the font size of my text. The functionality is there, but I want to establish a limit on how small or large the font can go. Here's what my current code looks like: <md-button ng ...

I am encountering an issue while attempting to set up admob for my react native application, as I am facing

Encountering an error The file "/BuildProductsPath/Release-iphoneos/XCFrameworkIntermediates/GoogleAppMeasurement/WithoutAdIdSupport/GoogleAppMeasurement.framework/GoogleAppMeasurement(APMAdExposureReporter.o)" does not have bitcode. Suggestions include r ...

How can I make a DIV grow taller without impacting neighboring DIVs?

I am working on expanding a specific DIV within a series of DIVs for an image gallery. However, I am facing an issue where when I expand the particular DIV, it affects all the following ones and causes them to shift positions, leaving a large blank space t ...

What is the process for updating tabs and their content in React?

Here is where the error occurs in my JavaScript code. I have successfully implemented it in HTML, CSS, and simple JavaScript, but encountered issues when trying to do so in React. My goal is to switch tabs and their corresponding data/content: ...

Issues with Vue-select dropdown functionality are causing inefficiencies

I am utilizing vue-select to generate a standard drop-down menu. However, it comes with a search bar by default that I do not need and prefer to keep it simple. I attempted to hide the search bar by using "display: none" which made it disappear. This is t ...