Skip to content

Commit 1014bfa

Browse files
committed
Fix ask function
1 parent c79d769 commit 1014bfa

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/interpreter.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,12 +273,14 @@ export class Interpreter {
273273
}),
274274
});
275275

276-
setFn("ask", (question: any) => {
276+
setFn("ask", (question: any = "", zero?: any) => {
277277
MainLoop.stop(); // FIXME: find another way to make this sync, please!
278278
let input = prompt(String(question)); // FIXME: rework into asynchronous style!
279279
MainLoop.start(); // FIXME:
280280

281-
return input;
281+
if (typeof zero == "number") return +(input || zero);
282+
if (typeof zero == "boolean") return !!(input || zero);
283+
return input || zero;
282284
});
283285

284286
setFn("print", (...words: any[]) => {

0 commit comments

Comments
 (0)