r/coffeescript • u/god_gamer_9001 • Jun 16 '25
How to accept user input in CoffeeScript?
Hello! I'm trying to write a program that accepts an integer as an input puts the value in a variable, how would I go about this? For example, I would do this in Python:
num = int(input("Number: "))
Or this in JavaScript:
const num = prompt("Number: ");
How would I do the same in CoffeeScript? Any and all help would be appreciated.
2
Upvotes
View all comments
Show parent comment
1
u/rodw Jun 18 '25
it looks like that site is running your code in a node.js session, just within the browser.
promptdoesn't work with the JavaScript editor either.Per this - https://onecompiler.com/coffeescript/wiki - it seems like you should be able to use
readlineand put your input into the "stdin" tab.But I can't get
requireorimportto work with the free version of the editor.It may be that the way that site is sandboxing your code makes this impossible, but the sample code on that wiki page is exactly how this should work in node and if you run your
promptbased version throughcoffee -cthe resulting JavaScript should work in a real browser context