// Function to calculate the factorial of a number
function calculateFactorial(n) {
if (n < 0) {
return "Factorial is not defined for negative numbers.";
} else if (n === 0 || n === 1) {
return 1;
} else {
let result = 1;
for (let i = 2; i <= n; i++) {
result *= i;
}
return result;
}
}
// Example usage
const number = 5;
console.log("The factorial of " + number + " is: " + calculateFactorial(number));
Snippets Plugin
No-code Prism.js integration for Wix sites
Themes
Default
Dark
Okaidia
Tomorrow Night
Twilight
Solarized Light
VS
VS-Dark
Shades of Purple
Hopscotch
GH Colors
Night Owl
1
Install the app from the app market. Add the widget to your page and place it anywhere on the canvas. You can place it off canvas by setting negative margins or delete the text elements to prevent interference.
2
Add text element, paste or type in your code. Turn on dev mode and add classes "snippet" and "lang-javascript" or your desired language. See documentation for more design options
Publish your page and view your code snippet on the live sight!
Full demo video below 👇
3