GAME DEV 2026 · JAVASCRIPT FUNDAMENTALS

t1a05 — Input / Output by Innes

JavaScript can read information from an input and display a result in an HTML element. This is called input and output (I/O).

Reference: JavaScript Input · JavaScript Output

Example code

const myIn01 = Number(document.getElementById('myNum01').value);
const myAnswer = myIn01 * 2;
document.getElementById('myDiv01').textContent = myAnswer;

The input element provides a value. JavaScript can process that value, then send a result to an output element. textContent displays text safely.

Try it — input and output

Output

Your result will appear here.

More input/output examples

One input can be used for several calculations. Try a percentage, a temperature conversion, or a word counter.

Challenge

Change the program so it calculates half of the number. Then add another button that displays the number multiplied by ten.

Think about it: What should happen if the input is empty?