Flatacuties is a fun app where users can vote for the cutest animal! This project demonstrates fetching data from a local JSON server and dynamically displaying content on a webpage with vanilla JavaScript.
- View all animals: A sidebar lists all animal names.
- View animal details: Click an animal name to see its image and current vote count.
- Vote for animals: Increases the number of votes for any animal locally.
- Reset votes: Reset an animal's votes back to 0.
-
Clone the repository:
git clone git@github.com:moses804/code-challenge-2.git cd flatacuties
-
Install JSON Server (if not already installed): npm install -g json-server
-
Create db.json and add the following data: { "characters": [ { "id": 1, "name": "Mr. Cute", "image": "https://thumbs.gfycat.com/EquatorialIckyCat-max-1mb.gif", "votes": 0 }, { "id": 2, "name": "Mx. Monkey", "image": "https://thumbs.gfycat.com/FatalInnocentAmericanshorthair-max-1mb.gif", "votes": 0 }, { "id": 3, "name": "Ms. Zebra", "image": "https://media2.giphy.com/media/20G9uNqE3K4dRjCppA/source.gif", "votes": 0 }, { "id": 4, "name": "Dr. Lion", "image": "http://bestanimations.com/Animals/Mammals/Cats/Lions/animated-lion-gif-11.gif", "votes": 0 }, { "id": 5, "name": "Mme. Panda", "image": "https://media.giphy.com/media/ALalVMOVR8Qw/giphy.gif", "votes": 0 } ] }
-
Start the backend server: json-server --watch db.json The server runs at: http://localhost:3000/characters
-
Open index.html in your browser to view the frontend
flatacuties/ index.html # Main HTML file style.css # CSS for styling index.js # JavaScript logic (fetch, render, vote) db.json # Local JSON server data
How It Works
-
Fetch & display animals
index.js fetches the data from /characters endpoint and displays all names in a sidebar.
-
Show animal details
Clicking a name renders the animal's image, name, and votes.
-
Vote & Reset
Clicking Vote increases the votes locally.
Clicking Reset sets votes back to 0.
-
Add new animal (bonus)
Users can submit a form with an animal name and image URL.
The new animal is added to the list (local only).
HTML – structure of the page
CSS – styling and layout
JavaScript – fetch API, DOM manipulation
JSON Server – local backend API
The content of this site is licensed under the MIT License. (c) 2025 Moses Maina