javascript - window.prompt alternative

Re: javascript - window.prompt alternative

por Jack Steel -
Número de respuestas: 1

I know you solved this another way, but there is a way to make your example code work if you wanted to use that/for future reference.

You'd need to override the window.prompt to return the test value.

Thus should be a working as a customized nodejs question with below as the template:


const window = {};

window.prompt = _ => {{ TEST.stdin }};

{{ STUDENT_ANSWER }}


Make sure it's not a combinator question and then the test cases should provide the input in the standard in.

Note we need to create the window object as it doesn't exist in the normal runtime, then we set the window.prompt function to take some ignored input and just return the TEST.stdin variable.

The only thing you'd need to change in your example code is using var/const to specify the variables:


const num = window.prompt("Number:");

console.log(num * 2);


See attached for an exported solution that's working as expected.