i399exlang/ex5.js

19 lines
264 B
JavaScript
Raw Permalink Normal View History

2017-03-30 13:59:37 +03:00
'use strict';
function factorial(n, callback) {
if (n < 0) {
throw 'illegal argument'
}
var result = 1;
while (n > 0) {
result *= n;
n--;
}
callback(result);
}
2017-04-06 13:28:05 +03:00
factorial(4, res => console.log(`Result: ${res}`))