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

Day / Days of Code: Deeper into JavaScript

王林
Release: 2024-08-30 19:03:04
Original
966 people have browsed it

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++;
Copy after login

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!

source:dev.to
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template