Text goes in quotes. + adds numbers and joins text; if either side is text, TB joins.
let cups = 2
let drink = "tea"
say("Cups of " + drink + ": " + cups)
say(cups * 3, true, nil)
Square brackets make a list. Positions start at 0, and push adds to the end.
let snacks = ["mango", "chips"]
push(snacks, "chocolate")
say(snacks)
say(snacks[0], len(snacks))
Only false and nil count as no. Everything else is yes.
let hour = 22
if hour >= 22 {
say("Time for bed.")
} else if hour >= 18 {
say("Evening!")
} else {
say("Still daytime.")
}
for walks through a list or text; while repeats while something is true.
for i in range(1, 4) {
say("Hug number " + str(i))
}
let n = 3
while n > 0 {
say(str(n) + "...")
n = n - 1
}
Functions are values. A function made inside another remembers the boxes around it.
fn make_counter() {
let count = 0
return fn() {
count = count + 1
return count
}
}
let hugs = make_counter()
hugs()
say("Hugs so far: " + str(hugs()))
ask waits for an answer (in the browser, a little box pops up). care says something kind.
let name = ask("What's your name? ")
say("Nice to meet you, " + name + "!")
care(name)