-
Notifications
You must be signed in to change notification settings - Fork 0
/
js.js
55 lines (45 loc) · 1.5 KB
/
js.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// creating an array holding all search results
let available_words = new Array(
'Nyanya Abuja to Biyan sokoto',
'Wuse Abuja to Waru Adamawa',
'Ajah Lagos to Garriki Enugu',
'Mbano Imo to Ikoyi Lagos',
'Nyanya Abuja to Biyan sokoto',
'Arochukwu Imo to Ikeja Lagos',
'Wuye Abuja to Benin-city Edo',
'Nike Enugu to Aba Abia',
'Garriki Enugu to Owerri Imo',
'Makurdi Benue to Lekki Lagos',
'Adamawa Yola to Kano Kano',
'Biku Yola to Kaduna Kaduna',
'Lokoja Kogi to Ikoyi Lagos',
'Lekki Lagos to Osogbo Osun',
'Awka Anambra to Kubwa Abuja',
'Awka Anambra to Suleja Niger'
);
const results_box = document.querySelector('.result-box');
const input_box = document.querySelector('#input-box');
input_box.oninput = ()=> {
let result = new Array();
let input = input_box.value;
if (input.length) {
result = available_words.filter((keyword)=>{
return keyword.toLowerCase().includes(input.toLowerCase());
});
console.log(result);
}
display_outputs(result);
if (!result.length) {
results_box.innerHTML = "";
}
}
function display_outputs(result) {
const content = result.map((list)=>{
return "<li onclick=selectinput(this)>" + list + "</li>";
});
results_box.innerHTML = "<ul>" + content.join('') + "</ul>";
}
function selectinput(list) {
input_box.value = list.innerHTML;
results_box.innerHTML = ""; // hide all elements when clicked on one
}