Which values will be returned?

HOTSPOT
You are validating user input by using built-in JavaScript functions.
The application must:
Store the value that is entered in a variable named inputValue
Use the built-in isNaN(tnputValue) function to evaluate the data type
You need to validate the return value of the isNaN(inputValue) function.
Which values will be returned? (To answer, configure the appropriate options in the dialog box in
the answer area.)

HOTSPOT
You are validating user input by using built-in JavaScript functions.
The application must:
Store the value that is entered in a variable named inputValue
Use the built-in isNaN(tnputValue) function to evaluate the data type
You need to validate the return value of the isNaN(inputValue) function.
Which values will be returned? (To answer, configure the appropriate options in the dialog box in
the answer area.)

Answer:



Leave a Reply 19

Your email address will not be published. Required fields are marked *


M

M

Correct answers:

-13 False
24.3 False
3*8 False
‘5’ False

To check this, go to any other website than this, press F12, go to console and enter:
isNaN(-13) + ‘ ‘ + isNaN(24.3) + ‘ ‘ + isNaN(3*8) + ‘ ‘ + isNaN(‘5’);
This will produce the following:
false false false false

hus

hus

isNaN(“3*8”) == true

test

test

The question doesn’t have quotes around 3*8. M is correct.

Lab

Lab

I’ve couldn’t belive this myself so i’ve tested them all on sure enough M is right all of the is false.

S

S

I’ve some doubts. The task is to validate user input value that we stored in variable named ‘inputValue’.
So, if user enters value in input, e.g. 3*8 and then we get this value with jQuery:

var inputValue = $(‘#someInputValue’).val(); // inputValue = ‘3*8’ -> string
isNaN(inputValue) == true

Same is if user enter string ‘5’ in input.

Yes, M is right when we open developer tool and type directly this values into isNaN function we will get everything as false. But the task is to validate user input.

Can someone give feedback?

Franco2000

Franco2000

“You’re validating user input”, so if an user inputs “3*8” its obvious that using NAN we’re gonna get True, the same for ‘5’. You’re right S.

M DUONG

M DUONG

So in this case, all is true, i think

Damien

Damien

I assume that the user inputs the value into a form and the .val() function is used to get the value. The .val() function returns a string. This is very important to the answer, but only if this assumption is true.

If you go here: http://www.w3schools.com/jsref/jsref_isNaN.asp

and click on the first “Try It” you will see a list of isNaN test examples. Change the function contents to:

var a = isNaN(-13) + “”;
var b = isNaN(“-13”) + “”;
var c = isNaN(24.3) + “”;
var d = isNaN(“24.3”) + “”;
var e = isNaN(3*8) + “”;
var f = isNaN(“3*8”) + “”;
var g = isNaN(‘5’) + “”;
var h = isNaN(“‘5′”);

var res = a + b + c + d + e + f + g + h;
document.getElementById(“demo”).innerHTML = res;

You will see that the results are:

false
false
false
false
false
true
false
true

The answers given by aiotestking are correct.

Umer Khalid

Umer Khalid

Agreed !

debbie

debbie

M is correct. All give false according to the details given in the link below
http://www.w3schools.com/jsref/jsref_isNaN.asp

In the example they have given
var c = isNaN(5-2) + “”; is the same as isNaN(3*8)
var e = isNaN(“123”) + “”; is the same as isNaN(‘5’)

Shahid Mahmood Khawaja

Shahid Mahmood Khawaja

Correct Answer is false, false, false, false

http://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_isnan

The isNaN() function returns true if the value is NaN (Not-a-Number), and false if not.

Click the button to check whether a number is an illegal number.

Try it

function myFunction() {
var a = isNaN(“-3.2”) + “”;
var b = isNaN(-1.23) + “”;
var c = isNaN(5-2) + “”;
var d = isNaN(0) + “”;
var e = isNaN(“123”) + “”;
var f = isNaN(“Hello”) + “”;
var g = isNaN(“2005/12/12”);

var res = a + b + c + d + e + f + g;
document.getElementById(“demo”).innerHTML = res;
}

J

J

Agree with Al… please look at his http://jsfiddle.net/q3u2w3bu/ . This is the correct context for the question. User uses a Form and literally inserts the values given.

stenly

stenly

false
false
true
true

no doubt about it