79217289

Date: 2024-11-23 06:37:14
Score: 0.5
Natty:
Report link

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();
Reasons:
  • Blacklisted phrase (1): What is your
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: Bachi