Skip to content

Instantly share code, notes, and snippets.

@agp745

agp745/Factorial Secret

Created February 14, 2023 19:46
Show Gist options
  • Save agp745/c55ed66419b212b50d79ff63dd13702d to your computer and use it in GitHub Desktop.
Save agp745/c55ed66419b212b50d79ff63dd13702d to your computer and use it in GitHub Desktop.
function factorialOf(inputNum) {
let num = parseInt(inputNum);
let result = 1;
for (let i = 2; i <= num; i++) {
result *= i;
}
return result;
}
let inputNum = prompt("enter a number to calculate its factorial");
let factorial = factorialOf(inputNum);
console.log(factorial);
function palindromeChecker(word) {
let wordArr = word.split("");
let revWord = [];
for (let i = wordArr.length - 1; i >= 0; i--) {
revWord.push(wordArr[i]);
}
let newWord = wordArr.toString();
let newRevWord = revWord.toString();
if (newWord === newRevWord) {
return true;
} else {
return false;
}
}
let word = prompt("Enter a word to check if it is a palindrome or not: ");
let answer = palindromeChecker(word);
console.log(answer);
function isPrime(inputNum) {
let num = parseInt(inputNum);
if (num === 1 || num === 2) {
return "is prime";
} else {
let i = 2;
while (i < num) {
if (num % i === 0) {
return "not prime";
}
i++;
}
return "is prime";
}
}
let inputNum = prompt("input a number to check if it is prime: ");
let answer = isPrime(inputNum);
console.log(answer);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment