Thu, August 29, 2024
Today, I continued my journey through Codecademy’s Full Stack Engineer path. One thing I’ve noticed is that while the syllabus provides a solid framework, there are often additional layers of learning beneath and between assignments.
In the Number Guessing Game Project, the task was to write well-defined control flow functions. This went quite quickly for me. From what I’ve seen on the Codecademy forums, only about 5% of students used arrow functions for this project. I opted for arrow functions because they improve concision and readability, especially for one-liners. One important thing to remember with arrow functions is that they cannot be hoisted, so their order of declaration matters. Otherwise, there were no surprises. Here’s my implementation:
let humanScore = 0;
let computerScore = 0;
let currentRoundNumber = 1;
const generateTarget = () => Math.floor(Math.random() * 10);
const getAbsoluteDistance = (number1, number2) => Math.abs(number2 - number1);
const updateScore = winner => winner === 'human' ? humanScore++ : computerScore++;
const compareGuesses = (humanGuess, computerGuess, secretTarget) =>
getAbsoluteDistance(humanGuess, secretTarget) <= getAbsoluteDistance(computerGuess, secretTarget);
const advanceRound = () => currentRoundNumber++;
After wrapping up the first JavaScript Syntax lesson, I jumped right into the second lesson and completed the first assignment on Arrays. Learning that arrays declared as const are mutable was a mind-blowing revelation! With Arrays down, I’m now moving on to Loops and then Objects. I’m really enjoying how Codecademy provides resources and then lets us explore on our own.
Top comments (0)