Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"liveServer.settings.port": 5501
}
1 change: 1 addition & 0 deletions lib/index.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

<!DOCTYPE html>
<html>
<head>
Expand Down
103 changes: 103 additions & 0 deletions lib/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@



// catButton.addEventListener('click', function(){
// fetch(url,{header})
// .then((response) => response.json())
// .then((result) => {
// console.log('Success:', result);
// })
// .catch((error) => {
// console.error('Error:', error);
// })
// })


// fetch(url,{header})
// .then((response) => response.json())
// .then((result) => {
// console.log('Success:', result);
// })
// .catch((error) => {
// console.error('Error:', error);
// }):

// const url = `https://api.thecatapi.com/v1/images/search`
// let header={
// "x-api-key":
// "live_c7NFwQNovYorkhRwoYbtV1ytRgM1c7I3KmWGi5ucgGsnk1aBvtmJfe4HDV36SJzd"}
// const randomButton= document.querySelector('.randomButton')
// const kittyIMG= document.querySelector('.categoryCatImage')
// const apiKey= "live_c7NFwQNovYorkhRwoYbtV1ytRgM1c7I3KmWGi5ucgGsnk1aBvtmJfe4HDV36SJzd"

// randomButton.addEventListener("click", function(){

// fetch(url, {header})
// .then((response) => response.json())
// .then((response) => { kittyIMG.src = `${response[0].url}`})
// })

// const url = `https://api.thecatapi.com/v1/images/search`

// const randomButton = document.querySelector('.randomButton')

// const kittyIMG = document.querySelector('.categoryCatImage')


// randomButton.addEventListener('click', function(){

// fetch(url, {header})
// .then((response) => response.json())
// .then((response) => { kittyIMG.src = `${response[0].url}`})

// const apiKey = 'live_c7NFwQNovYorkhRwoYbtV1ytRgM1c7I3KmWGi5ucgGsnk1aBvtmJfe4HDV36SJzd'
// let header = {
// "x-api-key": 'live_c7NFwQNovYorkhRwoYbtV1ytRgM1c7I3KmWGi5ucgGsnk1aBvtmJfe4HDV36SJzd'
// }
// const url = `https://api.thecatapi.com/v1/images/search`
// const randomButton = document.querySelector('.randomButton')
// const kittyIMG = document.querySelector('.categoryCatImage')


// randomButton.addEventListener('click', function(){

// fetch(url, {header})
// .then((response) => response.json())
// .then((response) => { kittyIMG.src = `${response[0].url}`})

// })

// const apiKey = 'live_c7NFwQNovYorkhRwoYbtV1ytRgM1c7I3KmWGi5ucgGsnk1aBvtmJfe4HDV36SJzd'

// const url = `https://api.thecatapi.com/v1/images/search/?api_key=${live_c7NFwQNovYorkhRwoYbtV1ytRgM1c7I3KmWGi5ucgGsnk1aBvtmJfe4HDV36SJzd}`

// const randomButton = document.querySelector('.randomButton')

// const kittyIMG = document.querySelector('.categoryCatImage')


// randomButton.addEventListener('click', function(){

// fetch(url)
// .then((response) => response.json())
// .then((response) => { kittyIMG.src = `${response[0].url}`})

// })

const url= "https://api.thecatapi.com/v1/images/search"
let header = {
"x-api-key":
"live_c7NFwQNovYorkhRwoYbtV1ytRgM1c7I3KmWGi5ucgGsnk1aBvtmJfe4HDV36SJzd"
}
const catButton = document.querySelector(`.randomButton`);
catButton.addEventListener('click', handleClick)
//click is just the name of it( it can be press or buttun etc)

function handleClick() {
fetch(url, {header})
.then((res) => res.json())
.then((res) => {
let randImage = document.querySelector(".randomCatImage");
randImage.src = res[0].url;
});
}