Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8510385
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T03:41:22+00:00 2026-06-11T03:41:22+00:00

Create a HTML page which accepts user input into the text field as integer

  • 0

Create a HTML page which accepts user input into the text field as integer between 10 and
120. When the user pressed the “Display” button, your function created in JavaScript should
able to display all prime integer between 1 and 120.

Example

Input Integer:
20

The Function should return:
1, 2, 3, 5, 7, 11, 13, 17, 19

function primeNumbers(){
var p;
var n = document.primeForm.primeText.value;
var d;
var x;
var prime;
var displayAll = 2 + " ";
for(p = 3; p <= n; p = p+2){
    x = Math.sqrt(p);
    prime=1;
    for(d = 3; prime && (d <= x); d = d+2)
    if((p%d) == 0)
        prime = 0;
    else
        prime = 1;
    if(prime == 1){ 
        displayAll = displayAll + p + " ";
    }
}
document.primeForm.primeArea.value = displayAll;

}​

but it can display more than 120 🙁

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T03:41:24+00:00Added an answer on June 11, 2026 at 3:41 am

    The for loop is where everything is happening. So if the value is outside of the range that you want, then don’t allow the for loop to execute. In order to do this, place an if statement around the for loop.

    Since you only plan to use these numbers once, it doesn’t matter if you enter in the min/max directly in the if statement or if you make a variable to hold the value. Most people suggest keeping all of your variables at the top in case you ever need to change the range: it’s easier to find them.

    On to the if statement: n is the deciding factor in whether or not to execute the for loop. Here is the statement: if (n >= 10 && n <= 120) { insert the for loop here }. All you’re doing is checking if the input is greater than or equal to 10 AND checking that the input is less than or equal to 120.

    Note: if you don’t want anything displaying, then include the line right after the for loop that is outputting the results in the if statement.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I create a new page using HTMl and I whant when user clicks on
I cannot create Mongo varibale in JSP file: <%@ page language=java contentType=text/html; charset=ISO-8859-1 pageEncoding=ISO-8859-1%>
I am trying to create a simple test HTML page which shows messages from
I am trying to create a static HTML page which has a <form> which
I would like to create a PHP page which accepts an arguement like so:
I wanted to create an HTML page which would have a set search criterias.
Ive created a function which returns all the obserables items in my html page.
I want to create a html page that get data from a website table
I used to be able to do this to create an exported HTML page
I'm using SharpZipLib to create a zip file with an html page and images.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.