Question

PLs someone pls help me by editing my code to calculate the 4 pair of range to calculate the prim...

PLs someone pls help me by editing my code to calculate the 4 pair of range to calculate the prime numbers by using web workers(You will have to use 4 workers).

(I already have the code to manipulate the prime numbers but I need your help with web worker part)(code is below)

Can someone pls help with the code of computing prime number for four pair of an integer values by using web worker concept ! Appreciate all the effort!

--create a program using html5, css3, and javascript(In javascript pls use web workers for thread to compute the number of prime numbers in that range ).

--The interface permits the user to compute the number of primes in ranges of integer values.
--The interface should present the user with 4 pairs of "number" boxes in which 4 pairs of integer values can be entered.

(you will need four workers to compute the thread)

-- Each pair of values should be used by a thread to compute the number of prime numbers in that range, inclusive.
-- If any box is empty, then no thread should be created to compute the (empty) range.
--Provide a start button that the user can click when the above values have been entered.
--Finally, when the computation is complete, the number of primes in all ranges should be displayed on the page with a brief meaningful message.

--It is valid to assume that no range of numbers will include a number smaller than 3. All ranges are inclusive.

please take an idea of how the output should look like in the below picture!

0 0
Add a comment Improve this question Transcribed image text
Answer #1

***************Main.Js************************

// This is my main.js file

// First fetch data from boxes using getElementById
// Let's say i have number pair as:

var left1 = 1
var right1 = 8

var left2 = 1
var right2 = 8

var left3 = 1
var right3 = 8

// var left4 is empty
// var right4 is empty


var count=0;

// Now, Let's call worker for each pair...
// so, we have a worker.js file to compute prime in range
if(left1!=null){
   var worker1 = new Worker('worker.js');

   // sending param to worker to compute
   worker1.postMessage({left:left1,right:right1});

   // Listener to get return value from worker
   worker1.addEventListener('message', function(e) {
       count = count + e.data;
   }
}

if(left2!=null){
   var worker2 = new Worker('worker.js');
   worker2.postMessage({left:left2,right:right2});
   worker3.addEventListener('message', function(e) {
       count = count + e.data;
   }
}

if(left3!=null){
   var worker3 = new Worker('worker.js');
   worker3.postMessage({left:left3,right:right3});
   worker3.addEventListener('message', function(e) {
       count = count + e.data;
   }
}

if(left4!=null){
   var worker4 = new Worker('worker.js');
   worker4.postMessage({left:left4,right:right4});
   worker4.addEventListener('message', function(e) {
       count = count + e.data;
   }
}

// Now, you have total no of prime in count variable you can use it.

************Worker.Js******************

// This is worker.js file

self.addEventListener('message', function(e,f) {
  
// let's say prime_in_range function will find no of prime...
var count = prime_in_range(e.data.left,f.data.right);

// sending back count to main thread
self.postMessage(count);
self.close();
}

Add a comment
Know the answer?
Add Answer to:
PLs someone pls help me by editing my code to calculate the 4 pair of range to calculate the prim...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Please please help with the code! Apperciate all the effort --create using html5, css3, and javas...

    Please please help with the code! Apperciate all the effort --create using html5, css3, and javascript. --The interface permits the user to compute the number of primes in ranges of integer values. --The interface should present the user with 4 pairs of "number" boxes in which 4 pairs of integer values can be entered. Each pair of values should be used by a thread to compute the number of prime numbers in that range, inclusive. -- If any box is...

  • Add JavaScript code in the “find_primeV2.js” to allow users to enter a number, and then based...

    Add JavaScript code in the “find_primeV2.js” to allow users to enter a number, and then based on the number of user enters, to find out how many prime numbers there are up to and including the user inputted number and then display them on the web page. The following are the detailed steps to complete this assignment: Step 1. [30 points] In “find_primeV2.js”, complete isPrime() function by (1) Adding one parameter in function header. That parameter is used to accept...

  • Could anyone help add to my python code? I now need to calculate the mean and...

    Could anyone help add to my python code? I now need to calculate the mean and median. In this programming assignment you are to extend the program you wrote for Number Stats to determine the median and mode of the numbers read from the file. You are to create a program called numstat2.py that reads a series of integer numbers from a file and determines and displays the following: The name of the file. The sum of the numbers. The...

  • I need help in C++ assignment. please add statements and i am Xcode complier user. Requested...

    I need help in C++ assignment. please add statements and i am Xcode complier user. Requested files: CountDecades.cpp (Download) Maximum upload file size: 96 KiB Write a C++ program named CountDecades.cpp. In this program you will have two integer arrays. One named inputArray of size 20 containing the values: 83, 2, 23, 11, 97, 23, 41, 67, 16, 25, 1 , 4, 75, 92, 52, 6, 44, 81, 8, 64 in the order specified, and an empty integer array of...

  • IT Review    JAVASCRIPT (Can someone please help me answer the below questions. It would be nice...

    IT Review    JAVASCRIPT (Can someone please help me answer the below questions. It would be nice if you add comments explaining what you are doing? If unable to add comments the answer would be fantastic. Thank you. Given the following function definition: function percent(x) {      return x / 100; } Which of the following statements correctly calls the percent function: percent(10); percent: 10; percent(); percent = 10; Indicate whether each of the following evaluates to true or false, given...

  • Help with a Parallel and Distributed Programming assignment. In this assignment, you will be expl...

    Help with a Parallel and Distributed Programming assignment. In this assignment, you will be exploring different methods of counting the prime numbers between 1 and N. You will use 8 threads, and each will be given a range in which to count primes. The question is: where do you store your counter? Do you use a local variable? Do you use a global variable? Please use the following function to determine whether an integer number is a prime. // Return...

  • Can someone help me with the main class of my code. Here is the assignment notes....

    Can someone help me with the main class of my code. Here is the assignment notes. Implement project assignment �1� at the end of chapter 18 on page 545 in the textbook. Use the definition shown below for the "jumpSearch" method of the SkipSearch class. Notice that the method is delcared static. Therefore, you do not need to create a new instance of the object before the method is called. Simply use "SkipSearch.jumpSearch(...)" with the appropriate 4 parameter values. When...

  • PLEASE HELP! python code Problem 4. Define the function pythagorian_coprimes (n=100) that prints all pairs of...

    PLEASE HELP! python code Problem 4. Define the function pythagorian_coprimes (n=100) that prints all pairs of positive integer numbers (a, b) such that c = a + b is also a whole number and 1 <c<n. Include only those triples that are co-prime (do not have any common divisors other than 1). For example, (3, 4, 5) is okay but (30, 40, 50) should be skipped. Help: As a starting example, examine the function pythagorian_triples that yields all triples. Modify...

  • This is a matlab HW that I need the code for, if someone could help me figure this out it would b...

    This is a matlab HW that I need the code for, if someone could help me figure this out it would be appreciated. The value of t can be estimated from the following equation: in your script file, estimate the value of π for any number of terms. You must ask the user for the desired number of terms and calculate the absolute error/difference between your calculation and the built-in MATLAB value ofpi. Display your results with the following message...

  • Can someone help me with this code, I not really understanding how to do this? import...

    Can someone help me with this code, I not really understanding how to do this? import java.util.ArrayList; import java.util.HashMap; import java.util.Map; /** * @version Spring 2019 * @author Kyle */ public class MapProblems { /** * Modify and return the given map as follows: if the key "a" has a value, set the key "b" to * have that value, and set the key "a" to have the value "". Basically "b" is confiscating the * value and replacing it...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT