Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

functions.js Please write these functions by Javascript A) Write a function name

ID: 3842486 • Letter: F

Question

functions.js

Please write these functions by Javascript

A) Write a function named isWhiteSpace() that accepts a character and returns true if it is a white space, false otherwise. Use a RegExp.

Hint: s - Matches a single white space character, including space, tab, form feed, line feed.

D) Write a function named isPalindrome, that accepts a sentence containing blanks and punctuation and returns true if it's a palindrome, false otherwise. HINT: reverseStr from P3 has a role to play here.

E) Write a function named factorial() that accepts a positive integer N and returns N!

F) Write a function nChooseK(), that accepts two positive integers, N and K, and returns the number of ways to arrange K items out of a set of N. You should use factorial() in this function.

G) Write a function factorsOfN(), that accepts a positive integer N, and returns an array containing all of its factors.

H) Write a function isPrime(), that accepts a positive integer and returns true if it is a prime, false otherwise. You should use factorsOfN() in this function.

Explanation / Answer

Question E

<!doctype html>
<html>
<head>
<script>
function factorial(){

var j, num, fact1;
fact1=1;
num=Number(document.getElementById("num").value);
for(j=1; j<=num; j++)
{
fact1= fact1*j;
}
document.getElementById("answer").value= fact1;
}
</script>
</head>
<body>
Enter Num: <input id="num">
<button>Factorial</button>
<input id="answer">