Created
August 8, 2023 18:02
-
-
Save luizpicolo/2007ff9abcee7b3337da1246e53e1bb1 to your computer and use it in GitHub Desktop.
readline.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const readline = require('readline'); | |
// Configurar a interface para leitura do terminal | |
const rl = readline.createInterface({ | |
input: process.stdin, | |
output: process.stdout | |
}); | |
// Perguntar ao usuário e processar a entrada | |
rl.question('Digite um número para ver sua tabuada: ', (input) => { | |
const numero = parseInt(input); | |
if (!isNaN(numero)) { | |
console.log(`Número digitado foi ${numero}:`); | |
rl.close(); | |
} else { | |
console.log("Número inválido. Tente novamente."); | |
rl.close(); // Fechar a interface de leitura em caso de número inválido | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment