Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <!--
- To change this license header, choose License Headers in Project Properties.
- To change this template file, choose Tools | Templates
- and open the template in the editor.
- -->
- <html>
- <head>
- <title>TODO supply a title</title>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- </head>
- <body>
- <div>Numeros primos até 1000</div>
- <script>
- var verificaPrimo = (numero) => {
- var divisores = 0,
- divisor = 1;
- while(divisor <= numero) {
- if (numero % divisor == 0) {
- divisores++
- }
- if (divisores > 2) {
- return false;
- } else {
- if (divisor == numero) {
- return numero;
- }
- }
- divisor++;
- }
- }
- var x = 1; primos = [];
- while (x < 1000) {
- if (verificaPrimo(x)) {
- primos.push(x)
- }
- x+=2;
- }
- console.log(primos)
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement