-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogtype.js
37 lines (35 loc) · 985 Bytes
/
logtype.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/*
Write a function named logType that expects a single argument and logs a different string depending on the type/value of the argument that is passed to it. The string it logs should be one of the following:
"undefined!"
"null!"
"number!"
"not a number!"
"string!"
"boolean!"
"function!"
"object!"
"array!"
"I have no idea!" */
//----------------------------------------------------------------------------------------------------------------------------------------------------------
function LogType(arg) {
var type = typeof arg;
if (isNaN(arg) === true && type === "number") {
console.log("not a number!");
} else if (arg === null) {
console.log("null!");
} else if (Array.isArray(arg) === true) {
console.log("array!");
} else {
console.log('"' + type + '!"');
}
}
var x;
var nn = NaN;
LogType("hello");
LogType({});
LogType([10, 20, 30]);
LogType(null);
LogType(true);
LogType(x);
LogType(function f() {});
LogType(nn);