-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
67 lines (57 loc) · 1.72 KB
/
app.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
56
57
58
59
60
61
62
63
64
65
66
67
//chat bot code
let trigger = [ ['hi'] ];
let reply = [ ['Hi, im chat bot'] ];
document.querySelector('#input').addEventListener('keypress', (e)=>{
var key = e.which || e.keyCode;
if(key ===13){
let input = document.querySelector('#input').value;
document.querySelector('#user').innerHTML = input;
output(input);
}
});
function output(input){
try{
let product = input + '=' + eval(input);
} catch{
let text =(input.toLowerCase()).replace(/[^w\s\d]/gi, '');
if(compare(trigger, reply, text)){
let product = compare(trigger, reply, text);
} else{
var product = text;
}
}
document.querySelector('#chatBot').innerHTML = product;
document.querySelector('#input').value = '';
}
function compare(arr, array, string){
var item;
for(var x = 0; x < arr.length; x++){
for(var y = 0; y< arr.length; y++){
if(arr[x][y] == string){
items = arrey[x];
item = items[Math.floor(math.random()*items.length)];
}
}
}
return item;
}
// side bar code
var sideBar = document.getElementsByClassName("sideBar");
var i;
for (i = 0; i < sideBar.length; i++) {
sideBar[i].addEventListener("click", function() {
this.classList.toggle("active");
var content = this.nextElementSibling;
if (content.style.display === "block") {
content.style.display = "none";
} else {
content.style.display = "block";
}
});
}
//search bar code
var submit = document.getElementById("submit");
// function submit()
submit.addEventListener('click', ()=>{
alert('no results found');
});