Frontend
Frontend API Interaction – script.js
The file `script.js` handles form submissions and frontend-to-backend communication. It gathers input values from HTML elements, packages them into a JSON payload, and sends them via the Fetch API to the Flask server. Error responses are caught and displayed gracefully. The JavaScript also formats and renders the returned sentiment and answer list in the frontend UI dynamically.
UI Structure and Styling – index.html & style.css
The user interface is built using HTML5, styled with modern CSS for responsiveness and dark mode compatibility. Elements include: - Coin selection dropdown (`<select>`) - Query input field (`<input>`) - Submission button (`<button>`) - Output div (`<div id="result">`)
Light Frontend work:
script.js
Purpose: Bridges frontend form with backend API.
Core Logic:
Sends a POST request to /query
Parses and displays response
Handles errors and displays fallback messages
Helper:
const capitalize = str => str.charAt(0).toUpperCase() + str.slice(1);
Used to format the coin name before displaying.
index.html and style.css
index.html: Standard HTML form including:
Dropdown for coin selection
Input field for query
Submit button to trigger sendQuery()
Result placeholder
style.css:
Custom styling:
Dark theme with soft shadows
Responsive form fields
Visual feedback on hover
Links:
Quick Links for reference:
Flask
Flask-CORS
render_template
request.get_json()
JSON module
os module
datetime
Fetch API
HTML form elements
CSS styling
Last updated