Code · 1 file
Sample CoffeeScript File
CoffeeScript, which compiles to JavaScript. Every language sample implements the same small program so you can compare them side by side.
CoffeeScript · 475 B
Sample CoffeeScript file
An idiomatic CoffeeScript example — the same customer program (or, for hardware languages, a small counter design) we offer in every language.
CC0 · free for any use · Verified by an independent tool · Report a problem
# Sample CoffeeScript — samplefiles.com
class Customer
constructor: (@id, @name, @balance) ->
isVip: -> @balance >= 10000
customers = [
new Customer(1, 'Ada', 12500)
new Customer(2, 'Grace', 830.5)
new Customer(3, 'Linus', 10000)
]
for c in customers
console.log "#{c.name.padEnd(6)} #{c.balance.toFixed(2).padStart(10)} #{if c.isVip() then 'VIP' else ''}"
total = customers.reduce(((sum, c) -> sum + c.balance), 0)
console.log "Total: #{total.toFixed(2)}"File details
Download from the command line
curl -L -o sample.coffee https://files.samplefiles.com/code/coffee/sample.coffeewget https://files.samplefiles.com/code/coffee/sample.coffeehttps://files.samplefiles.com/code/coffee/sample.coffeeprintf '%s %s\n' 6626effcac41f658b3d8251c8a19ccfe56c08fe9ae885a852d59f19c324e8f84 sample.coffee | shasum -a 256 -cOr check the download in your browser with the checksum calculator.