-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscripts2.js
142 lines (92 loc) · 3.33 KB
/
scripts2.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
function myFunction() {
alert("Fetching Results Please wait...");
const app = document.getElementById('root')
root.innerHTML="";
const container = document.createElement('div')
container.setAttribute('class', 'container')
app.appendChild(container)
var temp=document.getElementById("demo2").value;
document.getElementById("demo2").value=""
var n = temp.length;
var request = new XMLHttpRequest()
if(n>1)
request.open('GET', 'https://www.thecocktaildb.com/api/json/v1/1/search.php?s='+temp,true)
else
request.open('GET', 'https://www.thecocktaildb.com/api/json/v1/1/search.php?f='+temp,true)
request.onload = function() {
// Begin accessing JSON data here
var data = JSON.parse(this.response)
console.log(data)
if(data.drinks != null) {
if (request.status >= 200 && request.status < 400) {
data.drinks.forEach(wine => {
var img = document.createElement('img')
img.src = wine.strDrinkThumb
img.setAttribute('class', 'img3')
var move = document.createElement('a')
move.setAttribute('name','movelink' )
/*var ac = document.createElement('a')
ac.setAttribute('href', wine.strYoutube)*/
/*var img2 = document.createElement('img')
img2.setAttribute('class','ytube')
img2.src = 'youtube.png'*/
const card = document.createElement('div')
card.setAttribute('class', 'card')
const h1 = document.createElement('h1')
h1.setAttribute('class', 'hed1')
const h2 = document.createElement('h2')
h2.setAttribute('class', 'para1')
const p = document.createElement('p')
p.setAttribute('class', 'para1')
h1.textContent = wine.strDrink
h2.textContent='Instructions:'
p.textContent = wine.strInstructions
/*ac.appendChild(img2)*/
container.appendChild(card)
h1.appendChild(move)
card.appendChild(h1)
card.appendChild(img)
card.appendChild(h2)
card.appendChild(p)
/* card.appendChild(ac)*/
})
}
location.href='#movelink';
} else{ alert('drink doesnt exist in the API')}
}
request.send()
}
const app = document.getElementById('root')
const container = document.createElement('div')
container.setAttribute('class', 'container')
app.appendChild(container)
var request = new XMLHttpRequest()
request.open('GET', 'https://www.thecocktaildb.com/api/json/v1/1/random.php',true)
request.onload = function() {
if(this.status==200 && this.readyState==4) {
var data = JSON.parse(this.response)
console.log(data)
data.drinks.forEach(wine => {
var img = document.createElement('img')
img.src = wine.strDrinkThumb
img.setAttribute('class', 'img3')
const card = document.createElement('div')
card.setAttribute('class', 'card')
const h1 = document.createElement('h1')
h1.setAttribute('class', 'hed1')
const h2 = document.createElement('h2')
h2.setAttribute('class', 'para1')
const p = document.createElement('p')
p.setAttribute('class', 'para1')
h1.textContent = wine.strDrink
h2.textContent='Instructions:'
p.textContent = wine.strInstructions
container.appendChild(card)
card.appendChild(h1)
card.appendChild(img)
card.appendChild(h2)
card.appendChild(p)
})
}
}
request.send()