Skip to content
Open
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
25 changes: 25 additions & 0 deletions lib/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// part one


const url = 'https://api.thecatapi.com/v1/images/search'
const randomButton = document.querySelector('.randomButton');
const randomContainer = document.querySelector('.randomCat');
const form = document.querySelector("form");

randomButton.addEventListener("click", randomKitty);

function randomKitty () {
fetch(url)
.then(response => {
return response.json;
})
.then(data => {
let randomImage = document.querySelector('.randomCatImage');
randomImage.src = data[0].url;
})
.catch(error => {
console.log("something went wrong", error)
})
}