Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created January 31, 2019 17:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/88c5ce2492295b45046fbe92bb4711d4 to your computer and use it in GitHub Desktop.
Save parzibyte/88c5ce2492295b45046fbe92bb4711d4 to your computer and use it in GitHub Desktop.
const inputNumero = document.querySelector("#inputNumero"),
botonConvertir = document.querySelector("#botonConvertir"),
salida = document.querySelector("#salida");
// Escuchar el click del botón
botonConvertir.addEventListener("click", function () {
// Obtener valor que hay en el input
let valor = parseFloat(inputNumero.value);
// Simple validación
if (!valor) return alert("Escribe un valor");
// Obtener la representación
let letras = numeroALetras(valor, {
plural: "PESOS",
singular: "PESO",
centPlural: "CENTAVOS",
centSingular: "CENTAVO"
});
// Y a la salida ponerle el resultado
salida.innerText = letras;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment