Closed Zaindotea closed 9 months ago
Quokka runs in node, and prompt
(window.prompt
to be more precise) is a browser specific thing.
With the interactive nature of Quokka scratch pads, you are better off writing the answer to your prompt directly in your code file (e.g. assign it to a variable and use that variable).
While jsdom
emulates the browser behavior, it does not provide prompt
as a feature. This means it won't work for Quokka either.
You can emulate the behavior yourself (in your code) by replacing the prompt
function on window. For example:
console.log('foo');
window.prompt = () => {
return 'myVariable';
};
console.log(window.prompt('Enter your name')) // Will return 'myVariable'
In the example above, you won't see a prompt. Quokka does not allow for values to be interactively captured from you when you run your file. Instead, we expect you will edit your code to set/update the value.
Issue description or question
I'm using the "jsdom-quokka-plugin", I installed it, it works great, but everytime I type "prompt("")" I get an error in the Quokka console, the index.html does works as expected and so does the Javascript file, but I'm afraid it might cause trouble in the future, and also, it's annoying to have a red wall in the console I've attempted to solve this on my own with no success
Is this issue related to Quokka not outputting the expected results of your code?: Yes/No
Yes
It does not run using node.js in cmd, since i'm using the jsdom plugin
Sample code
Quokka.js Console Output
Code editor version
Visual Studio Code v1.81.1
OS name and version
Windows 11