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.coffee — first linesCoffeeScript
# 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

Size
475 B (475 bytes)
MIME type
text/coffeescript
SHA-256
6626effcac41f658b3d8251c8a19ccfe56c08fe9ae885a852d59f19c324e8f84
MD5
786427f1d8e7ef54f842a2a1626f91fb

Download from the command line

curl -L -o sample.coffee https://files.samplefiles.com/code/coffee/sample.coffee

Or check the download in your browser with the checksum calculator.