diff --git a/cat.css b/cat.css new file mode 100644 index 0000000..4d2e732 --- /dev/null +++ b/cat.css @@ -0,0 +1,47 @@ +.background-video { + position: fixed; + top: 0; + left: 0; + width: 100vw; + height: 100vh; + object-fit: cover; + z-index: -1; +} +body { + font-family: Arial, sans-serif; + text-align: left; + padding: 20px; +} + +button { + padding: 10px 20px; + background-color: blue; + color: white; + font-size: 16px; + border: none; + cursor: pointer; + border-radius: 5px; + display: flex; + justify-content: start; + +} + +button:hover { + background-color: darkblue; +} + +img { + margin-top: 20px; + max-width: 100%; + height: auto; + border: 2px solid #ccc; + border-radius: 8px; + display: flex; + justify-content: start; + +} + +p { + font-size: 18px; + margin-top: 10px; +} diff --git a/cat.js b/cat.js new file mode 100644 index 0000000..249adee --- /dev/null +++ b/cat.js @@ -0,0 +1,42 @@ +class CatFetcher { + constructor(apiKey) { + this.apiKey ="live_FDkCbFNEu4MQKmvu4P7zSoTQ3Tknntu3cqwtutIq8bASP7gsRozqMlgmiwObw1lR"; + this.apiUrl = "https://api.thecatapi.com/v1/images/search?include_breeds=true"; + + + // Select the necessary HTML elements + this.button = document.getElementById("getCat"); + this.imageElement = document.getElementById("catImage"); + this.breedElement = document.getElementById("breedName"); + + // Add event listener to the button + this.button.addEventListener("click", () => this.getRandomCat()); + } + + getRandomCat() { + // Fetch data from the API using the proxy and API key + fetch(this.apiUrl, { + headers: { "x-api-key": this.apiKey } + }) + .then(response => response.json()) // Convert the response to JSON format + .then(data => { + const catData = data[0]; // Get the first object from the API response + + if (catData && catData.url) { + this.imageElement.src = catData.url; // Set image source to the cat image URL + } else { + console.error("No image URL found in API response:", catData); + } + + // Display breed name if available, otherwise "Unknown Breed" + this.breedElement.textContent = catData.breeds.length > 0 ? catData.breeds[0].name : "Unknown Breed"; + }) + .catch(error => { + console.error("Error fetching cat:", error); + this.breedElement.textContent = "Failed to fetch cat. Try again!"; // Display error message + }); + } +} + +// Create an instance of the CatFetcher class with your API key +const catApp = new CatFetcher("live_FDkCbFNEu4MQKmvu4P7zSoTQ3Tknntu3cqwtutIq8bASP7gsRozqMlgmiwObw1lR"); diff --git a/image.png b/image.png new file mode 100644 index 0000000..9cb53fc Binary files /dev/null and b/image.png differ diff --git a/index.html b/index.html new file mode 100644 index 0000000..6363bce --- /dev/null +++ b/index.html @@ -0,0 +1,20 @@ + + + + + + Random Cat Fetcher + + + + + + image.png +

+ + + + diff --git a/rat.mp4 b/rat.mp4 new file mode 100644 index 0000000..94aeb6d Binary files /dev/null and b/rat.mp4 differ