Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

A) Write the isPrime function where indicated. The isPrime function should have one parameter and return true if it is a positive prime number and

A) Write the isPrime function where indicated. The isPrime function should have one parameter and return true if it is a positive prime number and false otherwise. No integer less than 2 should be considered prime, and no non-integer should be considered prime. Hints: You should use Number.isInteger to make sure that the given value is an integer before testing it for primality. Use a loop to try all divisors between 2 and one less than the number you're testing. If none of them evenly divides the number you're testing, then it is a prime. Remember that n1 % n2 === 0 is true if and only if n2 evenly divides n1. Your isPrime function should run quickly and accurately even for large numbers like 19999999.

B) Write the report function where indicated. The report function should have one parameter and output a string to the element with id equal to prime-or-not: If the parameter's value is a finite number and is prime, the function should output the string 'prime'. If the parameter's value is a finite number and is not prime, the function should output the string 'not prime'. If the parameter's value is not a finite number, the function should output the string 'not a number'. Your report function should call your isPrime function to test primality.

On part b I've started my report function like this ( down below) am i going in the right direction?

const report = function (num){ if(is.Finite(num) && isPrime(num)){ //checking to see if the number is finite and prime return prime; } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Jeff Hoffer, Ramesh Venkataraman, Heikki Topi

12th edition

133544613, 978-0133544619

More Books

Students also viewed these Databases questions

Question

Question Can a Roth IRA invest in stock of the IRA owners business?

Answered: 1 week ago