-
Notifications
You must be signed in to change notification settings - Fork 0
/
jokes.js
40 lines (32 loc) · 1.02 KB
/
jokes.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
let container=document.querySelector('.container');
let btn=document.querySelector('button')
let p=document.querySelector('#text')
let url= 'https://official-joke-api.appspot.com/jokes/random'
async function getjoke() {
let res=await fetch(url);
let data=await res.json();
console.log(data.setup+"\n"+data.punchline)
let joke=data.setup+"\n\n"+data.punchline
p.innerText=joke
}
btn.addEventListener('click',()=>{
getjoke();
})
// ----------------------------------------------------Quote----------------------------------------------------------------------
let btn1=document.querySelector('#butq')
let p1=document.querySelector('#quote')
let url1="https://type.fit/api/quotes"
btn1.addEventListener('click',function() {
quote();
})
function quote() {
fetch(url1)
.then((res)=>{
return res.json();
})
.then((data)=>{
let i=Math.floor(Math.random()*17)
p1.innerText=data[i].text+"\n\n"+data[i].author;
console.log(data[i].text+"\n\n"+data[i].author)
})
}