forked from trulyPranav/BoP-PreBuild
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
28 lines (26 loc) · 1.02 KB
/
Copy pathscript.js
File metadata and controls
28 lines (26 loc) · 1.02 KB
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
document.getElementById('api1button').addEventListener('click', async ()=>{
await fetch('https://official-joke-api.appspot.com/random_joke/')
.then(response => response.json())
.then(data => {
document.getElementById('api1displayer').innerText = JSON.stringify(data.setup);
document.getElementById('api1follower').innerText = JSON.stringify(data.punchline);
console.log(data)
})
})
document.getElementById('api3button').addEventListener('click', () => {
let titleHere = prompt("Enter a Title", 'hello');
let bodyHere = prompt("Enter a meesage", 'Hello World');
fetch('https://jsonplaceholder.typicode.com/posts',{
method: 'POST',
body: JSON.stringify({
title: titleHere,
body : bodyHere,
userId: 1
})
})
.then(response => response.json())
.then(data => {
console.log(data);
document.getElementById('api3displayer').innerText = JSON.stringify(data.id);
})
})