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.

  1. Write an outer if to check if typeof userEntry is strictly equal to "number".
  2. Inside this if block, write a nested if-else to check if userEntry is between 1 and 100 (inclusive):
    • If within range: Print "Valid number."
    • Otherwise: Print "Number out of range."
  3. Create an outer else (for non-numbers):
    • Print "Invalid type."

01EXAMPLE 1

InputuserEntry = 20
OutputLogs: "Valid number."

Explanation: It is a number and it is between 1-100.

02EXAMPLE 2

InputuserEntry = "Hello"
OutputLogs: "Invalid type."

Explanation: typeof is "string", not "number".

Constraints

  • Use the typeof operator.
  • Use nested if statements.
  • Log messages must match exactly.
Control FlowConditionalsTypes
JavaScript
Loading...
5 Hidden

Input Arguments

userEntry20

Expected Output

Valid number.

Click RUN to test your solution