JavaScript Expressions
An example of using JavaScript expressions within widgets.
Fibonacci
Calculate fibonacci numbers
JavaScript code
function(n) { if (n == 0) { return 0 } else if (n == 1) { return 1 } else { return userdata.fibonacci(n - 1) + userdata.fibonacci(n - 2) } }
F0
0
F1
1
F2
1
F3
2
F4
3
F5
5
F6
8
F7
13
FizzBuzz
Calculate the "fizz buzz" interview question
JavaScript code
function(n) { if ((+n % 15) == 0) return { value: 'Fizz Buzz', color: 'red' } else if ((+n % 5) == 0) return { value: 'Buzz', color: 'green' } else if ((+n % 3) == 0) return { value: 'Fizz', color: 'blue' } else return { value: n } }
Number
Fizziness
1
1
2
2
3
Fizz
4
4
5
Buzz
6
Fizz
7
7
8
8
9
Fizz
10
Buzz
11
11
12
Fizz
13
13
14
14
15
Fizz Buzz
16
16