-
-
Save agp745/c55ed66419b212b50d79ff63dd13702d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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