Title: My string variable doesn't replace the number in my if statement
Tags: javascript;html;if-statement
Question: I want to print the err variable to the payment Id if downtimeTotal is NaN or null or 0 (so essentially if the user doesn't put any inputs) but the calculator still prints NaN.
<div class=&quot;totalwrapper&quot;&gt;Credit Total:$<span id=&quot;payment&quot; class=&quot;output&quot;&gt;</span&gt;</div&gt;
</div&gt;
<button id=&quot;btn&quot;&gt;Calculate</button&gt;
<script&gt;
let btn = document.getElementById('btn')
btn.addEventListener('click', function(){
let err = &quot;you didn't put any numbers in!&quot;
let rmr = document.getElementById('RMR').value;
let cam = document.getElementById('bcam').value;
let sens = document.getElementById('sensors').value;
let dayMonth = document.getElementById('days').value;
let bSensors = document.getElementById('badSensors').value;
let down = document.getElementById('daysDown').value;
let rmrCam = cam * 5 / dayMonth * down;
let getDowntime = rmr / sens / dayMonth * bSensors * down + rmrCam;
if (sens == 0 || NaN || null ) {
getDowntime = rmr / dayMonth * bSensors * down + rmrCam;
}
let downtimeTotal = getDowntime.toFixed(2)
if (downtimeTotal == NaN || null || 0.00){
document.getElementById(&quot;payment&quot;).innerHTML = err;
}else {
document.getElementById(&quot;payment&quot;).innerHTML = downtimeTotal;
}
})
</script&gt;
Comment: See [How do you check that a number is NaN in JavaScript?](https://stackoverflow.com/questions/2652319/how-do-you-check-that-a-number-is-nan-in-javascript) and [How to force JS to do math instead of putting two strings together](https://stackoverflow.com/questions/4841373/how-to-force-js-to-do-math-instead-of-putting-two-strings-together)

Comment: `NaN == NaN` is always false, iirc, disregarding your improper multiple or statement attempt


Here is another answer: It's a precedence problem in that you're comparing against NaN, then if that's not truty (which it never is), using null and if that's not truthy (which is never is) using zero. See the following as an example:
&gt; a = 0
&gt; (a == NaN || 0)
&gt; (a == (NaN || 0))
But it's also a logic problem in that you're trying to do three comparisons but only one of the ops is a comparison - so it still won't achieve what you want.
To get it working you'd to need to change:
if (sens == 0 || NaN || null ) {
if (sens == 0 || sens == NaN || sens == null) {
But that still won't work because, as stated above NaN == NaN is always false so what you need is something more like:
if (sens === 0 || sens === null || isNan(sens)) {
Comment for this answer: Good point. I was looking at the logic / precedence issues and didn't catch that. Answer updated.

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 2, 'ContentLicense': 'CC BY-SA 4.0', 'CreationDate': '2020:00:12/03/20', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<javascript><html><if-statement>', 'Title': "My string variable doesn't replace the number in my if statement", 'ViewCount': 41, 'id': 65131359, 'user_AboutMe': None, 'user_AccountId': 18947025.0, 'user_DisplayName': 'Gabriel Segura', 'user_Reputation': 1.0, 'user_Views': 8.0, 'user_id': 13825656.0}}