This solution works but input syntax is not as easy as in NodeJS:
$("Hello") - for string
.
$(25) - for number
.
$(true) - for bool
.
here is the code:
window.$input = (() => {
let waitingCallback = null;
Object.defineProperty(window, '$', {
get: () => {
if (waitingCallback) {
const callback = waitingCallback;
waitingCallback = null;
return callback;
}
return () => { };
}
});
return prompt => {
console.log(prompt);
return new Promise(resolve => waitingCallback = resolve);
};
})();
// modify the function body. use 'await $input()'
async function example() {
const name = await $input('What is your name?');
const age = await $input('How old are you?');
console.log(`Your name is ${name} and you are ${age} years old.`);
}
// do not forget to call the function
example();