Skip to content

Myzmi/CurrencyGuessr

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 

Repository files navigation

CurrencyGussr

This program is a web-based application titled CurrencyGuessr, developed using the Django framework, a high-level Python web framework that encourages rapid development and clean, pragmatic design. The application is designed as a game where players guess currency conversion rates, specifically focusing on the conversion rate from USD to TRY (Turkish Lira). The game aims to draw attention to the challenges of predicting currency rates in the context of Turkey's economy, which has been experiencing significant inflation and currency devaluation.

The JavaScript code embedded within the HTML document is crucial for the game's interactivity. It defines several key functions and event listeners:

randomRate():

This function makes an asynchronous GET request to the /get_random_object endpoint, presumably a Django view that returns a JSON object containing random currency rate information. Upon successful request, the function updates global variables yearR, monthR, and rateR with the year, month, and rate from the response, respectively. It also updates the UI to display the current date of the currency rate being guessed.

startGame():

This function initializes the game by hiding the main page and explanation text, displaying the game page, and calling randomRate() to fetch the first currency rate to guess.

Event listeners:

The program listens for the DOMContentLoaded event to ensure the DOM is fully loaded before attaching event handlers. It handles form submissions for starting the game, submitting guesses, and replaying the game. Each handler updates the UI and game state accordingly, such as updating scores, advancing turns, and showing/hiding elements.

Score Calculation:

When a guess is submitted, the program calculates the absolute difference between the actual rate and the player's guess, converts this difference to a percentage, and then calculates the score for the turn based on how close the guess was to the actual rate. The cumulative score is updated and displayed after each guess.

The game concludes when the number of turns specified by the player at the start has been reached. The final score and scores for each turn are displayed on the results page, where the player can choose to play again.

Additionally, the application includes a Django migration file, indicating the use of a Django model CurrencyRate to store currency rate information in a database. The model includes fields for year, month, and rate, corresponding to the year and month of the rate and the conversion rate from USD to TRY, respectively.

In summary, CurrencyGuessr is a dynamic web application that combines Django's backend capabilities with front-end technologies like HTML, CSS, and JavaScript to create an interactive game experience focused on the economic phenomenon of currency rate fluctuations.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors