Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8607387
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T03:20:43+00:00 2026-06-12T03:20:43+00:00

I am currently learning javascript and am trying to make a quiz in javascript

  • 0

I am currently learning javascript and am trying to make a quiz in javascript with radiobuttons by following the example provided in javascript_source.I am right now stuck in a situation where i would like the selected radiobuttons label color to be changed to red or green based on the answer selected.

I have put my code in jsfiddle , i am able to get it to work in ny browser, but i dont know why it doesnt seem to work in jsfiddle, the basic idea is the same , only i would like to change the color of the selected radio button label based on correct or wrong.

Any help regarding this would be grateful

**EDIT *
jsfiddle now works thanks to the comments below

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T03:20:45+00:00Added an answer on June 12, 2026 at 3:20 am

    Fixed it, http://jsfiddle.net/aEeKt/8/. What I did was just add to get the parent <li> and add a .correct or .incorrect class to it depending on the answer.

    HTML

    <h3>Web Design Quiz</h3>
    
    <form name="quiz">
    1. What does CSS stand for?
    <ul style="margin-top: 1pt">
      <li><input type="radio" name="q1" value="Colorful Style Symbols">Colorful Style Symbols</li>
      <li><input type="radio" name="q1" value="Cascading Style Sheets">Cascading Style Sheets</li>
      <li><input type="radio" name="q1" value="Computer Style Symbols">Computer Style Symbols</li>
    </ul>
    
    2. What does DHTML stand for?
    <ul style="margin-top: 1pt">
      <li><input type="radio" name="q2" value="Dramatic HTML">Dramatic HTML</li>
      <li><input type="radio" name="q2" value="Design HTML">Design HTML</li>
      <li><input type="radio" name="q2" value="Dynamic HTML">Dynamic HTML</li>
    </ul>
    3. Who created Javascript?
    <ul style="margin-top: 1pt">
      <li><input type="radio" name="q3" value="Microsoft">Microsoft</li>
      <li><input type="radio" name="q3" value="Netscape">Netscape</li>
      <li><input type="radio" name="q3" value="Sun Micro Systems">Sun Micro Systems</li>
    </ul>
    4. What does CGI stand for?
    <ul style="margin-top: 1pt">
      <li><input type="radio" name="q4" value="Cascading Gate Interaction">Cascading Gate Interaction</li>
      <li><input type="radio" name="q4" value="Common GIF Interface">Common GIF Interface</li>
      <li><input type="radio" name="q4" value="Common Gateway Interface">Common Gateway Interface</li>
    </ul>
    
    <input type="button" value="Get score" onClick="getScore(this.form)">
    <input type="reset" value="Clear answers">
    <p> Score = <strong><input class="bgclr" type="text" size="5" name="percentage" disabled></strong><br><br>
    Correct answers:<br>
    <textarea class="bgclr" name="solutions" wrap="virtual" rows="4" cols="30" disabled>
    </textarea>
    </form>
    

    Javascript ​

    // Insert number of questions
    var numQues = 4;
    
    // Insert number of choices in each question
    var numChoi = 3;
    
    // Insert number of questions displayed in answer area
    var answers = new Array(4);
    
    // Insert answers to questions
    answers[0] = "Cascading Style Sheets";
    answers[1] = "Dynamic HTML";
    answers[2] = "Netscape";
    answers[3] = "Common Gateway Interface";
    
    // Do not change anything below here ...
    
    function getScore(form) {
        var score = 0;
        var currElt;
        var currSelection;
        for (i = 0; i < numQues; i++) {
        currElt = i * numChoi;
        for (j = 0; j < numChoi; j++) {
            currSelection = form.elements[currElt + j];
            cParent = currSelection.parentNode;
            if (currSelection.checked) {
            if (currSelection.value == answers[i]) {
                score++;
                cParent.className = 'correct';
                break;
            }else{
                cParent.className = 'incorrect';
            }
            }
        }
        }
        score = Math.round(score / numQues * 100);
        form.percentage.value = score + "%";
        var correctAnswers = "";
        for (i = 1; i <= numQues; i++) {
        correctAnswers += i + ". " + answers[i - 1] + "\r\n";
        }
        form.solutions.value = correctAnswers;
    }​
    

    CSS

    li.correct{
        color: green;
    }
    li.incorrect{
        color: red;
    }
    ​
    

    ​

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently learning JavaScript, and I got stuck at the following problems: I
I am learning javascript and the Facebook API right now and I am trying
I am currently learning C, and am having some issues with trying to make
I'm learning JavaScript and I'm currently trying to figure out why (in Spidermonkey )
I'm currently learning JavaScript, but I'm very weak on the fundamentals. I'm trying to
I am currently learning Javascript, and I'd like to create my own Lorem Ipsum
I am currently learning Object oriented Javascript but it seems that the alert is
I am currently learning javascript and am a litte confused with passing parameters through
I'm new to JavaScript, and I'm currently learning about the so-called for... in loop.
I'm currently learning JavaScript, and I don't understand why it is important to encode

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.