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 8797987
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:58:26+00:00 2026-06-13T23:58:26+00:00

It is clear that I need to learn javascript. I am trying to write

  • 0

It is clear that I need to learn javascript. I am trying to write a test that will work offline so I can’t use PHP and I am using javascript instead. Right now I have a test that will give me the score for number of correct answers. The way I did it was to just add up the values where correct is 1 and incorrect is 0. So, I can get the number of correct answers. However, what I really want is to calculate the Kappa score. To do that I need to know the count for each group in this table:

           True
          Y      N
Tester  Y  11    01
        N  10    00

here is my quiz:

test

    <script type="text/javascript"> 

        function getRBValue(group) { 
        //loop
          for ( var b = 0; b < group.length; ++b ) { 
            if ( group[b].checked ) 
            return Number(group[b].value); 
            } 
            return 0; } 

        function Score(form) { 
            var total = 0; 
            for ( var q = 1; q <= 10; ++q ) { 
            total += getRBValue( form["q"+q] ); 
            } 
        form.score.value = total; 
        alert("You got " + total + " questions right!"); 
        } 

    </script> 

    </head> 
    <body> 


    <h1>test</h1> 

    <p>The following exam will allow you to evaluate your ability to grade Trachoma.</p> 
    </body> 

    <form name="prequiz" onsubmit="Score(this); return false;"> 


    <table cellpadding=15px border="0" width="65%" summary= "Questions and options are organized in a table.">
    <tbody> 
    <tr> <td>
    <b><img src="pics/1.jpeg"</b><br/> 
    <br/><input type="radio" name="q1" value="0" > Present<br/> 
    <br/><input type="radio" name="q1" value="1" > Absent<br/> 
    </td> </tr> 

    <tr> 
    <td>
    <b><img src="pics/2.jpeg"</b><br/> 
    <br/> <input type="radio" name="q2" value="0" > Present<br/> 
    <br/> <input type="radio" name="q2" value="1" > Absent<br/> 
    </td> </tr> 


    <tr> 
    <td>
    <b><img src="pics/3.jpeg"</b><br/> 
    <br/> <input type="radio" name="q3" value="1" > Present<br/> 
    <br/> <input type="radio" name="q3" value="0" > Absent<br/> 
    </td> </tr> 

    <tr> 
    <td>
    <b><img src="pics/4.jpeg"</b><br/> 
    <br/> <input type="radio" name="q4" value="0" > Present<br/> 
    <br/> <input type="radio" name="q4" value="1" > Absent<br/> 
    </td> </tr> 

    <tr> 
    <td>
    <b><img src="pics/5.jpeg"</b><br/> 
    <br/> <input type="radio" name="q5" value="0" > Present<br/> 
    <br/> <input type="radio" name="q5" value="1" > Absent<br/> 
    </td> </tr> 

    <tr> 
    <td>
    <b><img src="pics/6.jpeg"</b><br/> 
    <br/> <input type="radio" name="q6" value="0" > Present<br/> 
    <br/> <input type="radio" name="q6" value="1" > Absent<br/> 
    </td> </tr> 

    <tr> 
    <td>
    <b><img src="pics/7.jpeg"</b><br/> 
    <br/> <input type="radio" name="q7" value="0" > Present<br/> 
    <br/> <input type="radio" name="q7" value="1" > Absent<br/> 
    </td> </tr> 

    <tr> 
    <td>
    <b><img src="pics/8.jpeg"</b><br/> 
    <br/> <input type="radio" name="q8" value="1" > Present<br/> 
    <br/> <input type="radio" name="q8" value="0" > Absent<br/> 
    </td> </tr> 

    <tr> 
    <td>
    <b><img src="pics/9.jpeg"</b><br/> 
    <br/> <input type="radio" name="q9" value="1" > Present<br/> 
    <br/> <input type="radio" name="q9" value="0" > Absent<br/> 
    </td> </tr>  

    <tr> 
    <td>
    <b><img src="pics/10.jpeg"</b><br/> 
    <br/> <input type="radio" name="q10" value="0" > Present<br/> 
    <br/> <input type="radio" name="q10" value="1" > Absent<br/> 
    </td> </tr> 

    </tbody> </table> </center> 

    <br><br>

    <input type="submit" name="submit" value="Score exam now"> 
    <br/><br/>

    <b>Your score:</b><input type="text" name="score" readonly="readonly" />
    <br/>
    </form> </html>
  • 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-13T23:58:28+00:00Added an answer on June 13, 2026 at 11:58 pm

    In getRBValue, you loop through the group elements, of which there are always two. The first one is always the Present choice and the second is always the Absent choice. In your current code, you can distinguish these by the value of the loop variable b. However, I would rewrite your code as:

    var PP, // correct is Present; user answered Present
        PA, // correct is Present; user answered Absent
        PN, // correct is Present; user did not answer
        AP, // correct is Absent; user answered Present
        AA, // correct is Absent; user answered Absent
        AN; // correct is Absent; user did not answer
    
    function ScoreGroup(group) {
        var presentIsCorrect = Number(group[0].value);
        if (group[0].checked) {
            // user answered Present
            if (presentIsCorrect) {
                PP++;
            } else {
                AP++;
            }
        } else if (group[1].checked) {
            // user answered Absent
            if (presentIsCorrect) {
                PA++;
            } else {
                AA++;
            }
        } else {
            // user did not answer the question
            if (presentIsCorrect) {
                PN++;
            } else {
                AN++;
            }
        }
    }
    
    function Score(form) { 
        PP = PA = PN = AP = AA = AN = 0;
        for ( var q = 1; q <= 10; ++q ) { 
            ScoreGroup( form["q"+q] ); 
        }
        var totalCorrect = PP + AA;
        // TODO: compute kappa from PP, PA, PN, AP, AA, AN, and totalCorrect
        form.score.value = totalCorrect; 
        alert("You got " + totalCorrect + " questions right!");
    }
    

    You could accumulate the raw counts in a 2D array, but in my opinion using explicit variables makes for more readable (if more verbose) code.

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

Sidebar

Related Questions

OK, so I'm trying to learn JavaScript properly so that I can write good,
It's clear that you can use numeric characters in SQL table names and use
Edited again because it originally wasn't clear that I'm trying to initialize the arrays
I am trying to create a clear method that would clear the array I
As many developers will be I'm producing web based application that are using AJAX
It is clear that cross compilers will not be allowed by the Apple App
I wonder if anyone can help me learn how to correctly use glMultMatrix. I
So I'm trying to learn to write shaders and incorporate them into my OpenGL
I need to clean a string that comes (copy/pasted) from various Microsoft Office suite
It's clear that Apple has an OpenCL implementation based on Clang and LLVM. There's

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.