Home  >  Article  >  Web Front-end  >  Day / Days of Code: Deeper into JavaScript

Day / Days of Code: Deeper into JavaScript

王林
王林Original
2024-08-30 19:03:04943browse

Day /  Days of Code: Deeper into JavaScript

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. On the other hand, I was already running VS Code and Node.

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.

The above is the detailed content of Day / Days of Code: Deeper into JavaScript. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn