The Type-Safe Gate
MediumAcc. 91.2%
+25 XP 10
Double Validation
A professional guard checks both your ID and your clearance level. In code, we often use typeof to ensure the data is of the correct type (like a number) before checking its value.
The Assignment
Your function receives a parameter named userEntry.
- Write an outer
ifto check iftypeof userEntryis strictly equal to "number". - Inside this if block, write a nested
if-elseto check ifuserEntryis between 1 and 100 (inclusive):- If within range: Print "Valid number."
- Otherwise: Print "Number out of range."
- Create an outer
else(for non-numbers):- Print "Invalid type."
01EXAMPLE 1
Input
userEntry = 20Output
Logs: "Valid number."Explanation: It is a number and it is between 1-100.
02EXAMPLE 2
Input
userEntry = "Hello"Output
Logs: "Invalid type."Explanation: typeof is "string", not "number".
Constraints
- Use the typeof operator.
- Use nested if statements.
- Log messages must match exactly.
Control FlowConditionalsTypes
JavaScriptSystem handles I/O — write your function only
Loading...
5 Hidden
Input Arguments
userEntry20
Expected Output
Valid number.
Click RUN to test your solution