JavaScript Golf Project

2025-01-23

JavaScript Golf Project

Repository

This project was a golf scorecard using an external api to get information about a specific course and calculate the score based on par, yardage, and handicap.

Stack

Golf scoring implementation using vanilla JavaScript and XMLHttpRequest, tracking multiple players and course data.

Technology

  • Vanilla JavaScript (ES5/ES6)
  • XMLHttpRequest (pre-fetch era)
  • Custom CSS (SCSS sources included)
  • jQuery for DOM manipulation

Key Features

  • Switch statement
  • Self Invoked functions
  • Multi player tracking
  • Score calculation

Learning Focus

  • Using an external api
  • Manipulating data with JavaScript
  • Manually creating HTTP requests without a library
  • Modifying the DOM from JavaScript

Ramblings

Looking back at this particular project I am honestly horrified at the JavaScript patterns and structure past me wrote. I can already think of ways to make the JavaScript smaller and more efficient. For an example I've got like eight hardcoded arrays filled with zeros up at the top to control the data for each player. Arrays can be two dimensional past me! I also didn't really understand the concept of a map yet. Eight hardcoded arrays can become a single line with both of these concepts.

let players = Array(8).fill().map(() => Array(18 /* or num holes */).fill(0));

Once that is done the switch statement is no longer really needed and can instead be represented as such

players[player-1][hole-1] = scoreNumber

There's also some other iteration and potential helper functions that can be written but I'm not about to entirely refactor a project that no longer even has an api to connect to.

Next project: HTML5 Web Workers Demo