<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width">
<title>
Formulario con 2 botones
</title>
</head>
<body>
<form
action=javascript:procSuma()>
<h1>
Formulario con 2 botones
</h1>
<p>
<label>
a
<input id=inA type=number
required min="0.1" max="100"
step="0.1">
</label>
</p>
<p>
<label>
b
<input id=inB type=number
required min="0.1" max="100"
step="0.1">
</label>
</p>
<p>
<button>Sumar</button>
<button formaction="javascript:
procResta()">
Restar
</button>
</p>
</form>
<script>
function procSuma() {
const a = inA.valueAsNumber
const b = inB.valueAsNumber
const resultado = suma(a, b)
alert(
`${a} + ${b} = ${resultado}`)
}
function procResta() {
const a = inA.valueAsNumber
const b = inB.valueAsNumber
const resultado = resta(a, b)
alert(
`${a} - ${b} = ${resultado}`)
}
function suma(a, b) {
return a + b
}
function resta(a, b) {
return a - b
}
</script>
</body>
</html>