Lesson 7 of 7
Project: the Calculator
Your first real app! Two inputs, four operations, one display — exactly the pattern of every interface: read, compute, display.
Tip: write a compute(operator) function and wire every button to it, like in the previous level.
function compute(op) {
var a = Number(document.getElementById('a').value);
var b = Number(document.getElementById('b').value);
if (op === '+') { ... }
}🎯 Your goal
Build the calculator: inputs #a and #b, four buttons #add #sub #mul #div, and a display #result. Each button computes its operation (+, -, ×, ÷) with the values converted to numbers, and writes the result into #result.
PRO lesson
This advanced chapter is part of CodeAge PRO. Unlock it to keep your adventure going.
Discover PRO →