CodeAgeBy Sitezack
JavaScript for MakersDOM and events0 XP
Chapter progress0/6

Lesson 5 of 7

Calculate with inputs

value is always text: '8' + '5' gives '85'! Convert first with Number(value).

After the calculation, write the result to the page with textContent.

var a = Number(document.getElementById('a').value);
var b = Number(document.getElementById('b').value);
document.getElementById('result').textContent = a + b;

🎯 Your goal

On clicking #add, add the values of inputs #a and #b (converted with Number) and write the result into #result.

PRO lesson

This advanced chapter is part of CodeAge PRO. Unlock it to keep your adventure going.

Discover PRO