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.)
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.)
3*8 is false
Please check http://www.w3schools.com/jsref/jsref_isNaN.asp
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
isNaN(“3*8”) == true
The question doesn’t have quotes around 3*8. M is correct.
I’ve couldn’t belive this myself so i’ve tested them all on sure enough M is right all of the is false.
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?
“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.
So in this case, all is true, i think
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.
Agreed. Original answers are correct.
http://jsfiddle.net/q3u2w3bu/
Agreed !
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’)
When the argument to the isNaN function is not of type Number, the value is first coerced to a Number. The resulting value is then tested to determine whether it is NaN.
https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/isNaN
https://jsfiddle.net/tw45r39c/
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;
}
Remember that you are getting value from an INPUT. The value is always text.
Then the answer should be: false false true true.
https://jsfiddle.net/tw45r39c/
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.
I think given answers are correct, as values needs to be taken from user input.
Checked here
https://jsfiddle.net/wvtjw4su/
http://jsfiddle.net/q3u2w3bu/
false
false
true
true
no doubt about it