using advance TxSc, class
A Pen by Mink CBOS - Ephellon Dantzler on CodePen.
<script type=text/ts> | |
##!, strict mode required for advanced features | |
## +clean | |
## +eval | |
## +legacy | |
## +math | |
## +wordy | |
## +advance | |
## -hide | |
## -html-editor | |
## -js-editor | |
## -ugly | |
.PiggyBank { | |
@(max) { | |
@max = max. | |
@coins = 0. | |
@smashed = false. | |
} | |
add(amount) { | |
amount = amount or 1. | |
if @coins < @max and not @busted { | |
@coins += amount. | |
} | |
if @coins < @max { | |
@coins = @coins | |
}{ | |
@coins = @max | |
} | |
} | |
amount(value) { | |
if value { | |
% value equals @coins. | |
} | |
% @coins. | |
} | |
smashed() { | |
% @smashed. | |
} | |
smash() { | |
% @smashed = true. | |
} | |
toString() { | |
% "$" + (@amount() * 0.01). | |
} | |
} | |
#bank = new PiggyBank(500). ## $5 | |
$doc.body.$html += ("<b val>${bank.amount()}</b> <br>"). | |
bank.add(). | |
$doc.body.$html += ("<b val>${bank.amount()}</b> <br>"). | |
bank.add(23). | |
$doc.body.$html += ("<b val>${bank.toString()}</b> <br>"). | |
</script> |
<script src="http://codepen.io/Ephellon/pen/EVxVaJ.js"></script> |
body { | |
background: #000; | |
color: #fff; | |
font-family: arial, monospace; | |
} | |
b { | |
color: #ae94c0; | |
} | |
[var] { | |
color: #efc371; | |
} | |
[val] { | |
color: #dd925f; | |
} |
using advance TxSc, class
A Pen by Mink CBOS - Ephellon Dantzler on CodePen.