diff --git a/animals.js b/animals.js new file mode 100644 index 0000000..576c8e2 --- /dev/null +++ b/animals.js @@ -0,0 +1,84 @@ +const petsData = [ + { + petName: "Stella", + age: 7, + weightInKilos: 24, + breed: "Dalmation", + pic: "animals\\stella.png" + }, + { + petName: "Cody", + age: 8, + weightInKilos: 22, + breed: "Corgi", + pic: "animals\\cody.png" + }, + { + petName: "Mango", + age: 2, + weightInKilos: 11, + breed: "Persian", + pic: "animals\\mango.png" + }, + { + petName: "Lucy", + age: 4, + weightInKilos: 35, + breed: "Ball Python", + pic: "animals\\lucy.png" + }, + { + petName: "Buhmie", + age: 1, + weightInKilos: 28, + breed: "Bull-dog", + pic: "animals\\buhmie.png" + }, + { + petName: "Domino", + age: 8, + weightInKilos: .23, + breed: "Unknown", + pic: "animals\\domino.png" + }, +]; + +const showInfo = () => { + // get a handle to the input field and get the value + let petNumber = document.querySelector("#petNum").value; + + // the array is zero-based, so subtract 1 + petNumber = parseInt(petNumber) - 1; + + // get a handle to the paragraph + let selectedPetInfo = document.querySelector(".selectedPetInfo"); + + // get the correspoding petsData object + let pet = petsData[petNumber]; + + // set the information + selectedPetInfo.textContent = `${pet.petName} is a ${pet.breed} and is ${pet.age} years old.`; + let petPic = document.querySelector(".selectedPetPic"); + + // set the image + petPic.src = pet.pic; +} + + +// ------------------------------------------------------ +// JAVASCRIPT +// Get a handle to the petsInfo paragraph +let petsInfo = document.querySelector(".petsInfo"); + +// Add content by modifying the textContent property +petsInfo.textContent = `Welcome to our newist pet, $${petsData[petsData.length - 1].petName} the ${petsData[petsData.length - 1].breed}`; + +let petsList = document.querySelector(".petsList"); + +let allPetsList = `