JSFiddle - React, Tailwind, and code Playground
HTML
<header>
<h1>Plus- ja Kertolaskin</h1>
</header>
<section>
<p>
<input type="text" id="eka" value="0" />
<input type="text" id="toka" value="0" />
</p>
<p>
<input type="button" value="+" onclick="plus()" />
<input type="button" value="*" onclick="kerto()" />
</p>
<p>Laskimen antama vastaus: <span id="tulos"></span></p>
</section>
JavaScript
function haeNumero(tunnus) {
return parseInt(document.getElementById(tunnus).value)
}
function asetaTulos(tulos) {
document.getElementById("tulos").innerHTML = tulos
}
function plus() {
asetaTulos(haeNumero("eka") + haeNumero("toka"))
}
function kerto() {
asetaTulos(haeNumero("eka") * haeNumero("toka"))
}