Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>How to find item inside array</title>
- <style>
- #bt {
- display: block;
- font-size: 20px;
- font-family: verdana;
- width: 150px;
- border: none;
- outline: none;
- color: white;
- background-color: red;
- padding: 5px 0;
- }
- #pt {
- display: block;
- font-size: 30px;
- font-family: verdana;
- width: 250px;
- color: red;
- padding: 5px 0;
- margin: 5px 0;
- }
- </style>
- </head>
- <body>
- <center>
- <input id='pt' type='text' autocomplete="off">
- <button id='bt'>Search</button>
- <p id='p'></p>
- </center>
- <script>
- numbers = [6, 20, 19, 16, 24, 48, 8, 1];
- i = 0;
- bt.onclick = function() {
- x = setInterval(() => {
- if (numbers[i] == pt.value) {
- clearInterval(x);
- p.innerHTML = 'Number ' + numbers[i] + ' is inside this array';
- i = 0;
- } else {
- i++;
- if (i == numbers.length) {
- clearInterval(x);
- p.innerHTML = 'No match found';
- i = 0;
- }
- }
- }, 0);
- }
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement