Question

In: Computer Science

Using HTML and JavaScript, receive a positive number, n, and output all prime numbers that are...

Using HTML and JavaScript, receive a positive number, n, and output all prime numbers that are smaller than n and have a digit 7. For example, if n is 100, the program should output 7, 17, 37, 47, 67, 71, 73, 79, and 97.

Solutions

Expert Solution

CODE IN JAVASCRIPT:

const number=parseInt(prompt("Enter the value of n : ")); //this will create a dialogue box which prompts when we take input

if(number==1)

{

    console.log("The number is neither prime nor compsite")

}

for(let i=2; i<=number ;i++){ //checking for each integer between 2 to number

    var count=0; //if this count changes to 1 for a number then the number is not prime

    for(let j=2;j<=i/2;j++)

    {

        if(i%j==0)

        {

            count=1;

            break;

        }

       

    }

    if(count==0) //this means i is prime

    {

      var num=i; //this num is used to find all the integer with number 7

      while(num!=0)

      {

          if(num%10==7) //checking condition if there is 7 in the number

          {

              console.log(i);

              break;

          }

          num=num/10;

      }

    }


}

OUTPUT SNIPPET:


Related Solutions

Please Use JavaScript and HTML 5) Number guesser (easier) Create a number guessing name, using an...
Please Use JavaScript and HTML 5) Number guesser (easier) Create a number guessing name, using an input and a button to gather a number. The number to be guessed should be a hard-coded whole number between 1 and 20. Tell the user if the number is too high, equal to, or too low than a number you have hard-coded in your application. Remove the text in the input when the user clicks the button.
JavaScript (HTML) Task: Please read 10 numbers that are list below, sort the numbers and then...
JavaScript (HTML) Task: Please read 10 numbers that are list below, sort the numbers and then print those numbers. 10 numbers = { 9, 3, 2, 1, 10, 30, 4, 6, 7, 8} [Reference JavaScript code] <html> <body>     <H1>prompt()</h1>     <p id="pro"></p>     <script>        // Array creation        var num= new Array();               var ix = 0;        // Read 10 numbers        for (ix = 0; ix < 10; ix++)        {num[ix] = prompt("Enter a number");...
c# code working but output not right, I need to output all numbers like : Prime...
c# code working but output not right, I need to output all numbers like : Prime factors of 4 are: 2 x 2 here is just 2 Prime factors of 7 are: 7 Prime factors of 30 are: 2 x 3 x 5 Prime factors of 40 are: 2 x 2 x 2 x 5 here is just 2,5 Prime factors of 50 are: 2 x 5 x 5 here is just 2,5 1) How I can fix it 2)I...
Consider the statement, “For all natural numbers n,n, if nn is prime, then nn is solitary.”...
Consider the statement, “For all natural numbers n,n, if nn is prime, then nn is solitary.” You do not need to know what solitary means for this problem, just that it is a property that some numbers have and others do not. Write the converse and the contrapositive of the statement, saying which is which. Note: the original statement claims that an implication is true for all n,n, and it is that implication that we are taking the converse and...
For this assignment, you will write a tic-tac-toe application in HTML and JavaScript, using an HTML...
For this assignment, you will write a tic-tac-toe application in HTML and JavaScript, using an HTML <canvas> tag. The game will be played "hot seat" where players take turns using the same device. Requirements: The canvas should be 600px tall and wide, with the gameplay area occupying most of the canvas. The X's and O's may be drawn using polygons or large-font text The grid should be drawn using polygons, specifically long, thin rectangles Before & between games, the canvas...
Using the pumping lemma, prove that the language {1^n | n is a prime number} is...
Using the pumping lemma, prove that the language {1^n | n is a prime number} is not regular.
Build an application using HTML, CSS, javascript, json. It is not necessary for backend to be...
Build an application using HTML, CSS, javascript, json. It is not necessary for backend to be working but the frontend should be good. App should to simple and useful in our day to day life. For eg- grocery shopping list or alarm or weather forecast or reminder.
For this assignment you need to create a ToDo list using Javascript, along with HTML and...
For this assignment you need to create a ToDo list using Javascript, along with HTML and CSS. Begin by creating a HTML page called todo.html. Then create a Javascript file called todo.js and link it in to the HTML page using a script tag. All Javascript for the assignment must be in the separate file. (For CSS, feel free to include styles in a style block at the top of the HTML page, or to link in CSS from a...
For this assignment you need to create a ToDo list using Javascript, along with HTML and...
For this assignment you need to create a ToDo list using Javascript, along with HTML and CSS. Begin by creating a HTML page called todo.html. Then create a Javascript file called todo.js and link it in to the HTML page using a script tag. All Javascript for the assignment must be in the separate file. (For CSS, feel free to include styles in a style block at the top of the HTML page, or to link in CSS from a...
Let n be a positive integer. Prove that two numbers n2+3n+6 and n2+2n+7 cannot be prime...
Let n be a positive integer. Prove that two numbers n2+3n+6 and n2+2n+7 cannot be prime at the same time.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT