Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
function calculate_fact() {
clearFields();
expand_eval();
var num;
num = document.getElementById("num").value;
if (num >= 0) {
addToEval(fact(num));
Materialize.toast("You've been factorialed!", 4000) // 4000 is the duration of the toast
}
else {
Materialize.toast("Invalid! Insert positive integer!", 4000) // 4000 is the duration of the toast
}
}
function addToEval(str) {
$("#evaluation").append(str, "<br />");
}
function expand_eval() {
var elem = $("#evaluation");
var currHeight = elem.height();
var autoHeight = elem.css('height', 'auto').height();
elem.height(currHeight).animate({
height: autoHeight
}, 1000)
}
function fact(n) {
if (n == 0) return 1;
var val = n * fact(n-1);
addToEval(n + "! = " + val);
return val;
}
function clearFields() {
document.getElementById("evaluation").innerHTML = "";
}