Advertisement
1xptolevitico69

How to find item inside array

Dec 3rd, 2021
1,116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.35 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3.  
  4. <head>
  5.   <meta charset="UTF-8">
  6.   <meta http-equiv="X-UA-Compatible" content="IE=edge">
  7.   <meta name="viewport" content="width=device-width, initial-scale=1.0">
  8.   <title>How to find item inside array</title>
  9.   <style>
  10.     #bt {
  11.       display: block;
  12.       font-size: 20px;
  13.       font-family: verdana;
  14.       width: 150px;
  15.       border: none;
  16.       outline: none;
  17.       color: white;
  18.       background-color: red;
  19.       padding: 5px 0;
  20.     }
  21.  
  22.     #pt {
  23.       display: block;
  24.       font-size: 30px;
  25.       font-family: verdana;
  26.       width: 250px;
  27.       color: red;
  28.       padding: 5px 0;
  29.       margin: 5px 0;
  30.     }
  31.   </style>
  32. </head>
  33.  
  34. <body>
  35.   <center>
  36.     <input id='pt' type='text' autocomplete="off">
  37.     <button id='bt'>Search</button>
  38.     <p id='p'></p>
  39.   </center>
  40.  
  41.   <script>
  42.     numbers = [6, 20, 19, 16, 24, 48, 8, 1];
  43.     i = 0;
  44.     bt.onclick = function() {
  45.       x = setInterval(() => {
  46.         if (numbers[i] == pt.value) {
  47.           clearInterval(x);
  48.           p.innerHTML = 'Number ' + numbers[i] + ' is inside this array';
  49.           i = 0;
  50.         } else {
  51.           i++;
  52.           if (i == numbers.length) {
  53.             clearInterval(x);
  54.             p.innerHTML = 'No match found';
  55.             i = 0;
  56.           }
  57.         }
  58.       }, 0);
  59.     }
  60.   </script>
  61. </body>
  62.  
  63. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement