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

Write a javascript program that will ask user to enter two numbers. Your program

ID: 3802179 • Letter: W

Question


Write a javascript program that will ask user to enter two numbers. Your program will then find prime numbers between these two numbers inclusively. The output of your program would be a table which contains two columns. The first column would be those prime numbers your program found and the second column contains corresponding square of these prime numbers. For example, if use input 10 and 20, then the prime numbers between these two numbers would be 11, 13, 17, and 19. Then your program will output a table like the following. Note you only need to output at most four smallest prime numbers between these two numbers entered by the user.

Explanation / Answer

<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>Check a number is prime or not</title>
   <script>
  
   var numFirst=parseInt(prompt("Enter a First number="));
   var numSecond=parseInt(prompt("Enter a Second number="));
  
   document.write("<table>");
   document.write("<tr>");
   document.write("<th>prime</th>");
   document.write("<th>square</th>");
document.write("</tr>");
   for (var counter = numFirst; counter <=numSecond; counter++) {
  
   var notPrime = false;
for (var i = 2; i <= counter; i++) {
if (counter%i===0 && i!==counter) {
notPrime = true;
}
}
if (notPrime === false) {
                   document.write("<tr>");
                   document.write("<td>");
                   document.write(counter);
                   document.write("</td>");
                   document.write("<td>");
                   document.write(counter*counter);
                   document.write("</td>");
                   document.write("<tr>");
   }
}
document.write("</table>");
   </script>
</head>
<body>

</body>
</html>

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote