thecodezone.
The Code Zone
← Back to conditional choices

Beginner JavaScript · 30-minute coaching session

Is this call long enough?

One input. One rule. One decision. Build a small duration check from a blank file, then prove it works at the boundary.

Rob receives a 32-second duration, inspects its value, and checks it against a minimum of 30 seconds.
Receive, inspect, decide. The call duration is data; the minimum is the rule you apply to it.

Checking sign-in and saved work…

Sign in to save to your profile

Sign in to save your code, predictions, observations and explanations to your account across devices. Signed-out practice stays in this browser only. You can reset the editor after confirmation without erasing your written notes.

1 · Try first · 5 minutes

Your goal in plain English

A call must last at least 30 seconds to continue. Take one duration, turn it into a number, and print whether the call can continue. Exactly 30 seconds counts.

Try on your own for a minute or two before opening a hint. Use invented data only. This editor runs practice JavaScript, with no connection to a live workflow.

  • Declare input with a starting value of 32.
  • Declare durationSeconds to hold the result of Number(input).
  • Declare proceed and compare durationSeconds to 30. If it is 30 seconds or more, the result should be true. Otherwise, it should be false.
  • Print durationSeconds to the console using console.log.
  • Print proceed to the console using a separate console.log, so the two values appear on separate lines.

Use let or const. Comments are welcome, but are not required to pass. Keep the three variable names so the practice inputs can find your code.

EDIT JAVASCRIPT

CONSOLE OUTPUT

Predict the result, then choose Run code.

Loading the editor…

    A small hint

    Work in three stages. Store input, convert it with Number(input), then compare the converted value using >= 30. console.log(value) prints a value. Try writing just one stage and running it first.

    Available after a passing check or three unsuccessful checks. Hints are available now.

    Compare this with your code

    explained-solution.jsjavascript · example
    // Receive one invented duration in seconds.
    const input = 32;
    // Turn the supplied value into a number.
    const durationSeconds = Number(input);
    // Exactly 30 seconds counts as long enough.
    const proceed = durationSeconds >= 30;
    // Print the converted number first.
    console.log(durationSeconds);
    // Print the decision second.
    console.log(proceed);

    Number(input) returns a number when conversion is possible. >= includes the boundary itself. Blank text becomes 0; nonnumeric text becomes NaN. Both fail this comparison. The practice assumes a duration-like number or string; a full webhook validator needs additional rules. Opening this example does not change your code or pass the challenge.

    Editor and console stay together. Drag their divider, or focus it and press the arrow keys, to change their widths. On phones the console sits below the editor.

    2 · Predict, run, explain · 10 minutes

    Test the same code eight ways

    Choose Run this input to open a focused window. Predict the converted number and true-or-false decision, inspect your code with that input, then choose Run. Your prediction and actual console output are applied to the row automatically.

    These buttons run a temporary copy of your current code with only the starting input changed. They do not replace or reset the code in your editor. Blank means empty text, "", in this lesson.

    Your predictions and observations
    InputMy predictionRun current codeWhat I saw
    0

    Predict before running.

    2

    Predict before running.

    29

    Predict before running.

    30

    Predict before running.

    32

    Predict before running.

    49

    Predict before running.

    Blank (empty text)

    Predict before running.

    "45" (text)

    Predict before running.

    When you have tried the rows, use Check challenge by the editor. It checks your conversion, the comparison, these eight inputs and one invalid-text input. Passing checks validate this small task, not every possible webhook value.

    3 · Learn after trying · 10 minutes

    What happens between input and decision?

    Use the diagram to connect the input, conversion and decision. Predict first, then reveal the path.

    Number(): convert a value

    Number("45") returns the number 45. Quotes tell us the original value was text. Number(32) stays the number 32. Number("") returns 0, not NaN.

    NaN: conversion did not produce a usable number

    Number("hello") returns NaN, short for “Not a Number.” NaN >= 30 is false. Add an extra row in your conversation: what would your code print for "hello"?

    >= 30: include the boundary

    29 >= 30 is false. 30 >= 30 is true. Read the symbol as “greater than or equal to,” or “at least.” Using > alone would reject exactly 30.

    Connect this to a rejection check

    Your working comparison answers, “May this duration continue?” A rejection condition can ask the opposite using !(durationSeconds >= 30). Work from the inside out: compare first, then flip the boolean with !. This catches both short durations and NaN for this exercise. durationSeconds < 30 alone does not catch NaN.

    Number.isFinite("45") is false because it checks the supplied value without converting it. Number.isFinite(Number("45")) is true. A production validator should explicitly decide which incoming types and missing values are allowed.

    4 · Explain it back · 5 minutes

    You are the developer now

    Explain your code aloud before typing notes. Your coach can listen for the parts you can explain independently.

    Common mistakes: using > instead of >=, assuming blank becomes NaN, and confusing conversion with a check of the original value. A passing duration does not prove that a call was answered or that its content is useful.

    Follow the duration flowchart

    Choose an input and predict the decision before stepping through the diagram. This shows the intended duration rule, not a trace of your editor code. These discussion controls do not change your saved predictions or code.

    Input arrivesinput = 32
    Convert to a numberNumber(input)
    At least 30 seconds?durationSeconds >= 30
    Yes · true ↓

    Continue

    proceed = true
    No · false ↓

    Do not continue

    proceed = false

    Below 30, or NaN

    Make your prediction, then follow the input.

    Start with the input. Choose Next to convert it.

    Predict → run → compare

    Try one input with your code

    Your main editor stays unchanged. Predictions save as you type; running fills in What I saw.