Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function sumPrimeNonPrime(input) {
- let prime = 0;
- let nonPrime = 0;
- let index = 0;
- while (input[index] !== "stop") {
- let num = Number(input[index++]);
- if (num >= 0) {
- if (num % 2 === 0 || num % 3 === 0 || num % 5 === 0) {
- if (num === 2 || num === 3 || num === 5 || num === 7) {
- prime += num;
- } else {
- nonPrime += num;
- }
- } else {
- prime += num;
- }
- } else {
- console.log("Number is negative.");
- }
- }
- console.log(`Sum of all prime numbers is: ${prime}`);
- console.log(`Sum of all non prime numbers is: ${nonPrime}`);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement