I tried to create a JavaScript program that outputs the binary format of an English letter on input. I had to put the value in the code. How can the value be entered in the console when the program runs?
JavaScript
x
8
1
function returnBinaryLetter(char) {
2
return ((/^[a-z]$/).test(char)) ? char.charCodeAt(0).toString(2).padStart(8, '0') : 'Sorry, that is not a letter.'
3
}
4
5
// Something like:
6
// const input = consoleInputFunction('Enter a number.');
7
// console.log(returnBinaryLetter(input.toLowerCase()));
8
EDIT 1: This is not for a webpage. This is a JS program which I will run using Node.js. I require a solution with just JS, not with some framework (if that is even possible, mentioning just to be specific).
EDIT 2: I have made the code better after suggestions in Endothermic Dragon’s answer.