#made a calculator on prompt but its not working help

63 messages · Page 1 of 1 (latest)

burnt brook
#

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.

#

Bro I want to kms

#

No offense

#

Sorry

mighty briar
#

it alr lol

#

it jus confuses me

#

need time to learn but im stuck rn

burnt brook
#

"num1" is a string num1 is a variable that contains something

mighty briar
#

i had em w out strings

#

still gave the same error

burnt brook
mighty briar
#

did

#

still the same lol

burnt brook
#

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:

  1. 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
    
  2. 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:

  1. 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
    
  2. 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.

mighty briar
burnt brook
#

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.

mighty briar
#

wait so

#

i change

#

if (isNan (num1) || isNan(num2))

#

?

burnt brook
#

Yes

#

N ≠ n "num1" ≠ num1

mighty briar
#

a ok

#

UHHHHHHHHHHHHH

#

wait so

#

ion get it

#

i jus

#

change isnan (num1) to that/

#

?

#

or just isnan

#

god i alr hate js

burnt brook
mighty briar
#

ik that but

burnt brook
#

This is in every language btw

mighty briar
#

the code

#

it shows errors

#

:d

burnt brook
#

|| isNaN(num2)

mighty briar
#

OH WAIT

#

oh nah

#

bro how did i mess that up

burnt brook
mighty briar
#

thanks

#

sm

#

appreciate it

burnt brook
burnt brook
mighty briar
#

who tf trolls on a programming server

mighty briar
burnt brook
mighty briar
#

nope

#

i got an error

#

bc i forgot ;