Why I`m getting NaN ? Application seems to work but starting point is NaN. How can I solve this?

nan error python
how to handle nan in java
what is nan error
how to avoid nan in javascript
how to solve nan error in c
isnan
why am i getting nan in python
integer nan java

When I run this applicatio.n its working but instead of 0 or anything I get NaN as average and positive value. If I click on buttons I get exact values. App is working but I dont know how to remove this NaN when I start application all over again

import React, { useState } from 'react';
import { Table } from 'reactstrap';
import './App.css';


const App = () => {
  const [good, setGood] = useState(0)
  const [neutral, setNeutral] = useState(0)
  const [bad, setBad] = useState(0)

  const handleGood = () => {
   setGood(good + 1)
  }

  const handleNeutral = () => {
    setNeutral(neutral + 1)
   }

  const handleBad = () => {
   setBad(bad + 1)
  }

  const average =  (((good-bad)/(good + neutral + bad))*100).toFixed(1);
  const positive = ((good / (good + neutral + bad))*100).toFixed(1);

  if (average < 0) {
    alert('Your score is lower then 0')
  }
  return (
    <div className="container mt-5">
          <h1 className="text-center pb-2">Stankove ocene</h1>
      <Table bordered hover>
        <thead>
          <tr className="text-center">
            <th>#</th>
            <th><button className="btn btn-success" onClick={handleGood}>Good</button></th>
            <th> <button className="btn btn-primary" onClick={handleNeutral}>Neutral</button></th>
            <th><button className="btn btn-danger" onClick={handleBad}>Bad</button></th>
            <th><h5>Overall Feedback</h5></th>
            <th><h5>Average</h5></th>
            <th><h5>Positive</h5></th>
          </tr>
        </thead>
        <tbody>
          <tr className="text-center">
            <th scope="row">Feedback</th>
            <td><p>{good}</p></td>
            <td><p >{neutral}</p></td>
            <td><p>{bad}</p></td>
            <td><p>{good + neutral + bad}</p></td>
            <td><p>{average}%</p></td>
            <td><p>{positive}%</p></td>
          </tr>

        </tbody>
      </Table>


     </div>

  )
}


export default App;

I dont have any errors I just wont to get rid of NaN and to set value to zero. Still working on this app so i didnt made any component inside of a component yet so its a bit messy.

Thanks in forward.

The issue here is that during the initialisations all your state values are 0, so when you do (good-bad)/(good + neutral + bad) the first time, it evaluates to 0/0 and division by 0 returns NaN.

Also note that in case of counters like you have, if you need to increment the current state, it's better to use the functional form of setState since it will make sure to always get the latest value of the state:

const handleGood = () => {
  setGood(currentGood => currentGood + 1)
}

One way to fix this, would be to check if you're dividing by 0 methods and return 0 by default:

const formatValue = (val) => (val * 100).toFixed(1);

// Return array of values, where 1st item is average and second is positive
const getValues = () => {
  const divider = good + neutral + bad;
  if (divider === 0) {
    return ['0', '0'];
  }

  return [formatValue((good - bad) / divider), formatValue(good / divider)]
}

Usage, with array destructuring :

const [avg, positive] = getValues(); 

Pro WPF in VB 2010: Windows Presentation Foundation in .NET 4, For this technique to work, the property you're animating must have a see later (which require the use of a binding expression to get the ActualWidth value). NaN, and an exception will be raised when you attempt to start the animation. you use the current value as a starting point for an animation—it may change the​  "The Operating System is not presently configured to run this application." I have tried all the suggestions from Act! Knowledge Base and Community but have not solved the problem. This has included:-removing Office 365 and reloading, then doing the same with Act!-registering redemption.dll with regsvr32 -running both as Administrator. Any

0/0 has no reasonable interpretation at all, hence its NaN.

Pro WPF with VB 2008: Windows Presentation Foundation with .NET 3.5, For this technique to work, the property you're animating must have a see later (which require the use of a binding expression to get the ActualWidth value). NaN, and an exception will be raised when you attempt to start the animation. you use the current value as a starting point for an animation—it may change the​  Join GitHub today. GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together. Sign up.

I think this may be because you are trying to divide by 0. If you change one of your values of good, bad or neutral to 1, it starts showing numbers.

Pro WPF 4.5 in VB: Windows Presentation Foundation in .NET 4.5, You can't animate ActualWidth (it's read-only), but you can use it to set the From later (which require the use of a binding expression to get the ActualWidth value). NaN, and an exception will be raised when you attempt to start the animation. you use the current value as a starting point for an animation—it may change  CAN doesn't tx in Normal mode but seems to work in Loopback Hi guys, I'm trying to use ECAN to communicate between 2 dsPIC33EP128GP506. Since I'm a newbie in CAN comm. I tried to read carefully the processor documentation and follow the relative example.

Handbook of Research on New Solutions and Technologies in , Aggregator Under Neighborhood Area Network (NAN) The exchange of It covers from the start point of smart meters on customer side which is the most WAN applications, including wide-area control, wide-area monitoring and protection, have been identified as the next-generation solution to achieve power system  All the other outlets work fine. This electrical wiring question came from Richard, a Homeowner in St. Augustine, Florida. Dave’s Reply: Thanks for your electrical wiring question Paul. How to Troubleshoot and Repair Outlet Problems. Application: Troubleshooting Receptacle Outlets that do not work, or do not have full power.

Friendly work, Nay , then , what that he was coming to - morrow to fix the date of the ails you now ? Come , Nan , no tongue against his teeth ; but at last he said nonsense . I ' m going to set up for myself , you see , " Well , then , my lass , may I trust you to settle for we sat up high , Dick was His action and the sight of the bird seemed to  Repeating failures of convergences have been observed while attempting to solve Eq. directly by MODFLOW. That’s the reason why we don’t compare Green’s function from WOG to that from MODFLOW in Test Case 4 and Case 5. In contrast, WOG-based method seems work stably in all cases in our investigation here.

How can I fix the NaN error?, going to the line 112 the variable (at) will be set to NaN, that is why the code will or logicals but in fact it has the value NaN and therefore the error appeared. I'​ve solved in the past many situations of indetermination, like 0/0, inf/inf, . How to use simplot function in matlab so that I can plot graph of simulink in matlab? I am using version 11.1.0.0. I was able to get the page to open externally and as you mentioned it does not autofill. I would prefer to keep using the built in function on a single server entry instead of creating a Web Browser subentry for this, so we will just use it externally for now.

Comments
  • How can i solve 0/0...To set 0 as starting point instead of NaN? Would I need some conditional rendering?
  • Yea its that, but how can i solve this ? and put initial value as 0 instead of NaN