• API
• FAQ
• Tools
• Archive
SHARE
TWEET # Untitled a guest Mar 25th, 2019 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. function executeOperationsOnNumbers(op)
2. {
3.     var num;
4.     // - Begin switch
5.     switch(op)
6.     {
7.         // - Begin first case
8.         case "checkPrime":
9.             var sum;
10.             while (true)
11.             {
12.                 var data = window.prompt("Enter a positive number:");
13.                 var number = parseInt(data, 10);
14.                 sum = checkPrimeNumber(number);
15.                 // - This break exits the while loop
16.                 if (sum == true)
17.                 {break};
18.             }
19.             var num = + number + " is a prime number"
21.             output.innerHTML = num;
22.             console.log(num);
23.             // - This break ends the case
24.             break;
25.         case "findPrime":
26.             var sum;
27.             while (true)
28.             {
29.                 var data = window.prompt("Enter a positive number:");
30.                 var number = parseInt(data, 10);
31.                 sum = findPrimeNumbers(number);
32.                 // - This break exits the while loop
33.                 if(number > 0)
34.                 {break};
35.             }
36.             var num = "There are " + sum.length
37.             + " prime numbers <= " + number + "\n"
38.             + "Prime Numbers <= " + number + ": " + sum
39.
41.             output.innerHTML = num;
42.             console.log(num);
43.             // - This break ends the case
44.             break;
45.         case "calcSum":
46.
47.             var sum;
48.             while (true)
49.             {
50.                 var data = window.prompt("Enter a positive integer:");
51.                 var number = parseInt(data, 10);
52.                 sum = calculateSum(number);
53.                 if (Number.isInteger(sum) && sum> 0)
54.                 // - This break exits the while loop
55.                 {break};
56.             }
57.             var num2 = "The sum of the integers from 1 to "
58.                 + number + " is " + sum;
60.             output.innerHTML = num2;
61.             console.log(num2);
62.             // - This break ends the case
63.             break;
64.         // - Begin default
65.         default:
66.             console.log('default');
67.             // - This break ends the default
68.             break;
69.     }
70.     // - End switch
71. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!

Top