Thanks for your question :clap:, if someone gives you an answer it would be great if you thanked them with a :white_check_mark: in response. This response will earn you both points for special roles on this server.
#made a calculator on prompt but its not working help
63 messages · Page 1 of 1 (latest)
You have to use num1 and num2 not "num1" and "num2"
"num1" is a string num1 is a variable that contains something
Oh wait internet bad I cannot see error but do what I said anyway
Oh there is no sush a thing as isNan
You have to do num1 == NaN I believe
@burnt brook _0bits's Question:
how to check if something is NaN in js
To check if something is NaN (Not-a-Number) in JavaScript, you can use the isNaN() function or the Number.isNaN() function. Here's how you can use each approach:
-
Using
isNaN():const value = 10 / "abc"; // Performing a mathematical operation that results in NaN if (isNaN(value)) { console.log("The value is NaN"); } else { console.log("The value is not NaN"); }Output:
The value is NaN -
Using
Number.isNaN():const value = 10 / "abc"; // Performing a mathematical operation that results in NaN if (Number.isNaN(value)) { console.log("The value is NaN"); } else { console.log("The value is not NaN"); }Output:
The value is NaN
Both isNaN() and Number.isNaN() functions return true if the provided value is NaN; otherwise, they return false. However, note that isNaN() has some quirks, as it coerces non-numeric values to numbers before checking for NaN. On the other hand, Number.isNaN() performs a strict comparison and only considers values of the NaN type as NaN.
@burnt brook _0bits's Question:
no nodejs
In Node.js, you can also use the same isNaN() and Number.isNaN() functions to check if something is NaN. Here's an example:
-
Using
isNaN():const value = 10 / "abc"; // Performing a mathematical operation that results in NaN if (isNaN(value)) { console.log("The value is NaN"); } else { console.log("The value is not NaN"); }Output:
The value is NaN -
Using
Number.isNaN():const value = 10 / "abc"; // Performing a mathematical operation that results in NaN if (Number.isNaN(value)) { console.log("The value is NaN"); } else { console.log("The value is not NaN"); }Output:
The value is NaN
Both isNaN() and Number.isNaN() functions work similarly in Node.js as they do in JavaScript. They will return true if the provided value is NaN; otherwise, they will return false. Again, note that isNaN() coerces non-numeric values to numbers before checking for NaN, while Number.isNaN() performs a strict comparison and only considers values of the NaN type as NaN.
oh
Oh it's isNaN not isNan
N ≠ n
@burnt brook _0bits's Question:
does == NaN work here
In JavaScript, using the == operator to check if a value is NaN is not reliable. The == operator performs type coercion, which can lead to unexpected results.
Here's an example to illustrate the behavior:
const value = 10 / "abc";
console.log(value == NaN); // Output: false
Even though value is NaN, the expression value == NaN evaluates to false. This is because NaN is a special value in JavaScript, and it does not equal itself.
To properly check if a value is NaN, you should use the isNaN() or Number.isNaN() functions.
const value = 10 / "abc";
console.log(isNaN(value)); // Output: true
console.log(Number.isNaN(value)); // Output: true
Both isNaN() and Number.isNaN() will correctly determine that value is NaN.
a ok
UHHHHHHHHHHHHH
wait so
ion get it
i jus
change isnan (num1) to that/
?
or just isnan
god i alr hate js
Bro this is common sense capital ≠ small
ik that but
This is in every language btw
What problem
jus realized what was the problem when u said this
thanks
sm
appreciate it
Thanks god you ain't another troll
OH WAJT REACT WITH ✅
who tf trolls on a programming server
done
or maybe they are just too stupid but I refuse to believe this when you said you still got error I tough you did isnan or something