thecodezone.
The Code Zone
Short steps, at your pace · Free lessons and practice · Member video walkthroughs
Save your next small win.

Checking your account…

16.01 · Input & output / Learn · 5 min

Follow input into output

A program can read a value, use it, and send a response. Follow each step.

Activity 1 of 7 in Input & output

All courses

JavaScript Basics / 16.01

Follow input into output

Not started

A program can read a value, use it, and send a response. Follow each step.

More options
Rob receives an Ada name card as input, uses it at his laptop, then displays Hello, Ada! as output.
Rob’s comic strip · Input & output

Input, processing, output

Input is information the program receives, such as a typed name. Processing uses that value. Output is the response, such as a greeting printed in the terminal.

A terminal and a browser are different environments. Node.js can use its built-in readline module to ask questions in a terminal. LiveCodes runs browser JavaScript and cannot use Node’s require, process.stdin or readline.

Practice the calculation separately

Here rawAge represents a value that somebody typed. It is text, even though it contains digits. Adding one to text joins characters: "18" + 1 becomes "181".

Number(rawAge) converts this known numeric text to a number, so age + 1 becomes 19. This example assumes valid numeric input; a real form also needs validation.

Practice the calculation separately
example.jsjavascript · example
const rawAge = "18";
const age = Number(rawAge);
console.log(age + 1);

Know what conversion accepts

Number(" 20 ") is 20; Number("hello") is NaN; Number("") is 0. Blank input therefore needs a separate check if blank means missing. Don’t assume every entered string is a valid age.

The next video uses the terminal. A browser practice afterward isolates conversion so you can test and share that part here.

Convert a supplied text reply before calculating

Work through 3 focused steps. Read the explanation, type each requested change and check it before moving on. Your own code carries forward.

The mini-lesson opens in a new tab. Your own code carries forward; each step has a focused check and an optional hint.

Start mini-lesson(opens in a new tab)

3 steps · Saved work · Instant feedback

YOUR TURN

Try the examples on this page

Choose Load this code into the editor beside an example, then edit and Run code here. Predict what will print before running it. This is an exploration workspace, so there is no pass/fail challenge. Its saved work stays separate from the next practice activity.

Load an example, edit it and run it. Word wrap is enabled.

Work in VS Code instead

Copy the starter into a file named practice.js in VS Code. If Node.js is installed, open the terminal in that folder and run node practice.js. Compare the output with the task above. Automated challenge checks are available in the browser editor.

Code example
example.jsjavascript · example
const rawAge = "18";
const age = Number(rawAge);
console.log(age + 1);

Replace your editor code?

Your current work will be replaced. Choose Cancel to keep it.

Ready to try it?

Practice in your browser and see your results.

Progress details

Have a question?

Ask the Code Zone community.

Ask a question in The Code Zone (opens in a new tab)

Continue learning

ONE STEP FORWARD

Keyboard input starts as text; choose whether to keep it as text or convert it.