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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:47:34+00:00 2026-06-17T22:47:34+00:00

My script is returning NAN and I want it to show 0 instead. Using

  • 0

My script is returning NAN and I want it to show 0 instead.

Using || 0 has achieved this however it now returns 100 instead of 0 for var percentQ. What is causing it to return 100?

$('#observationTotalRefresh').on('click', function () {

    var 
    sumP = 0,
    sumQ = 0,
    countP = 0,
    countQ = 0;

    $('.observationPositive:not(:disabled)').each(function(){
        countP++;
        sumP += Number($(this).val());
    });
    $('.observationQuestionable:not(:disabled)').each(function(){
        countQ++;
        sumQ += Number($(this).val());
    });

    var percentP = 100/(1 + (sumQ/sumP)) || 0;
    var percentQ = (100 - percentP) || 0;

    $("#observationPositivePercentage").text(percentP.toFixed(0));
    $("#observationQuestionablePercentage").text(percentQ.toFixed(0));
    $("#observationTotal").text(sumP + sumQ);
});
  • 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-17T22:47:35+00:00Added an answer on June 17, 2026 at 10:47 pm

    If you do || 0 for percentP, you are ensuring that percentP is always a number. So, percentQ will always be 100 - percentP; if percentP is 0, then percentQ will be 100.

    Your math for percentages seems oddly fishy, though. Perhaps you wanted

    var percentP = 100 * sumP / (sumP + sumQ);
    

    instead? Then, it’s simply

    var percentP, percentQ;
    if(sumP == 0 && sumQ == 0) {
        percentP = percentQ = 0;
    } else {
        percentP = 100 * sumP / (sumP + sumQ);
        percentQ = 100 * sumQ / (sumP + sumQ);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using this code to submit a form to a php script: var valid
I used this code for sending and returning result. <script type=text/javascript> $(document).ready(function() { $('.special').click(function(){
aspx script: <script type=text/javascript> $(document).ready(function() { $(.div_soru).hide(); $(.div_soru).first().show(); $(.onceki).click(function() { if ($(this).closest(.div_soru).prev(.div_soru).html() != null)
This script saves the files as /home/name/main/all my files and stuff . I want
This code is returning blank array. I am posting to PHP script with code.
I'm using code from this answer: https://stackoverflow.com/a/6501353/494901 Basically when the timer ends, I want
I've got this 2 codes returning script error alert to me on Internet Explorer
I have this subroutine in my script and it is returning -1 as the
Now i have a method in my Ruby script code and basicaly its returning
I've got a small script which is returning a string/path. This path is an

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.