Quotes help make search much faster. Example: "Practice Makes Perfect"

Monday, December 10, 2012

Codeyear: Protecting against errors and crashes


//sample solution


// Write a function to get the factorial of a number.
function factorial(int){
//termination condition
if(int<0){
console.log("Invalid input. No negative numbers allowed.");
return;
}
//base case
else if(int===1){
return 1;
} else {
return int*factorial(int-1);
}
}
//check
console.log(factorial(-3));

No comments:

Post a Comment


This is an example of scrolling text using Javascript.

Popular Posts