31 lines
1.2 KiB
Plaintext
31 lines
1.2 KiB
Plaintext
# Kertoma — Factorial in Tampio
|
|
#
|
|
# Methods are defined as: "[param in genitive] [method name] on [expression]"
|
|
# The parameter "pieni luku" (small number) appears in genitive: "pienen luvun"
|
|
#
|
|
# "riippuen siitä, onko ... joko ... tai ..." = ternary expression
|
|
# "pienempi tai yhtä suuri kuin yksi" = "less than or equal to one"
|
|
# "kerrottuna ... kertomalla" = "multiplied by [factorial]"
|
|
# Multiplication uses adessive case: "kertomalla" = "by the factorial"
|
|
|
|
Pienen luvun kertoma on
|
|
riippuen siitä, onko se pienempi tai yhtä suuri kuin yksi,
|
|
joko yksi
|
|
tai pieni luku kerrottuna pienen luvun edeltäjän kertomalla.
|
|
|
|
# "edeltäjä" = "predecessor" — defines n-1 as a helper method
|
|
|
|
Luvun edeltäjä on se vähennettynä yhdellä.
|
|
|
|
# "Olkoon X uusi muuttuja, jonka arvo on Y" = declare variable X with value Y
|
|
|
|
Olkoon pieni muuttuja uusi muuttuja, jonka arvo on nolla.
|
|
|
|
# Page-load event: prompt for a number, display its factorial
|
|
# "luetaan luku" = "a number is read" (browser prompt)
|
|
# "näyttää ... kertoman" = "shows the factorial of..." (genitive: kertoman)
|
|
|
|
Kun nykyinen sivu avautuu,
|
|
pieneen muuttujaan luetaan luku
|
|
ja nykyinen sivu näyttää pienen muuttujan arvon kertoman.
|