Assignments
This repository contains all of the assignments exercises that need to be handed in for the JavaScript modules (i.e., JavaScript, Browsers and UsingAPIs) of the HackYourFuture curriculum.
TL;DR
We highly recommend that you go through this README in detail before starting to work on the assignments. Having said that, the essentials can be summarized as follows:
Important: If you are using a Windows-based computer, please type this command from a Windows Terminal window before you proceed:
git config --global core.autocrlf false
This will ensure that the line endings for text files are compatible with those used on MacOS and Linux-based computers.
- Fork the
HackYourAssignment/Assignments-CohortXX repository to your own GitHub account.
- Clone the fork to your local computer.
- Open the root folder of the repository in VSCode.
- When invited to do so, please install the recommended VSCode extensions.
- Run the command
npm install from the root folder of the repository.
- Make sure that you are on the
main branch (if not, check it out first).
- Create a new branch and name it (e.g., for week 2 of JavaScript)
YOUR_NAME-w2-JavaScript. Replace YOUR_NAME with your name. Note that you should not work on / modify the main branch.
- Start your work on the assignments for week 2.
- After finishing an assignment, use the command
npm test to test your solution.
- Fix any reported issues and rerun the test. Repeat until all issues are fixed.
- When all assignments are done, commit all changed files. This includes the modified exercises, the generated test summary (
TEST_SUMMARY.md) and test reports (EXERCISE_NAME.report.txt).
- Push the changes to your fork.
- Create a pull request against the
main branch of the HackYourAssignment/Assignments-CohortXX repository. For the title of your pull request use the same format as the branch name, e.g.: YOUR_NAME-w2-JavaScript.
Repeat steps 6-13 for each week. For subsequent weeks the mandated branch names are:
YOUR_NAME-w3-JavaScript
YOUR_NAME-w1-Browsers
YOUR_NAME-w1-UsingAPIs
YOUR_NAME-w2-UsingAPIs
For more information how to hand in your weekly assignments please refer to the Hand-in Assignments Guide.
Introduction
Throughout your HYF journey you will be asked to do certain exercises. This repository contains all of these exercises for the JavaScript modules (JavaScript, Browsers, UsingAPIs). The module repositories will tell you how to hand in the assignment, the curriculum will indicate what week you will need to do.
Note that a fork of this repository will be created on the HackYourAssignment GitHub account specifically for your cohort. The name of the repository will have the format Assignments-cohortXX where XX is your cohort number,
Installation
After forking and subsequently cloning your forked repository execute the following command from the command line to complete the installation:
npm install
This command:
- Installs required software dependencies from the Internet.
- Sets up folders and files used to track your progress.
VSCode
You will be spending a lot of time in VSCode while working with this repository. If you are new to VSCode please check out the VSCode Tips before continuing.
From the command line, while inside the Assignments-cohortXX folder, you can use this command to open VSCode (the . stands for the current directory):
code .
When working on your assignments it is strongly recommended to always open the Assignments-cohortXX folder in VSCode rather than one of its sub-folders. This gives VSCode and all its extensions the full view on the repository for the best overall developer experience.
Note that the name of the folder opened in VSCode can always be found in the EXPLORER panel ( ASSIGNMENTS_COHORT49 in the picture below):

Install Recommended VSCode Extensions
Important: When you open the repository for the first time you may see the dialog box shown below that invites you to install a set of recommended VSCode extensions. These extensions will provide useful help and guidance when you are creating and editing files in VSCode. Please install these extensions when invited to do so.

If, for some reason, the prompt to install the extensions does not appear then please install the extensions manually (click on the triangle below for details).
Manual installation
If for some reason you do not see the VSCode message box inviting you to install the recommended extensions you can do so manually by clicking the Extensions button in the VSCode sidebar, pressing the Filter button and then selecting Recommended from the drop-down menu as shown in the figure below. Please install all extensions listed under the Workspace Recommendations header.

Overview of the Directory Structure
The directory structure containing the assignment for a specific curriculum module (in Figure 1 below, the JavaScript module), looks like this:
Figure 1. Directory Structure for the 1-JavaScript folder.
A similar directory structure exists for the Browser module (2-Browsers) and the UsingAPIs module (3-UsingAPIs).
Each assignment folder contains files and (sometimes) sub-folders that make up the exercises. The exercises consist of starter files that you need to complete. Some exercises consist of a single JavaScript (for example, ex1-giveCompliment.js). Exercises that are browser-based are mostly contained in sub-folders (for example, ex1-bookList in the 1-Browsers/assignment folder).
You should not change anything in the unit-tests sub-folder. The purpose of this folder will be explained later.
As mentioned, each exercise comes with starter code. Inside the starter code you will find comments that indicate the places where there is something for you to do. For example, in the code of the JavaScript file ex1-giveCompliment.js as shown in Figure 2 this is:
- The parameter list (if needed, for you to figure out) of the function
giveCompliment.
- The function body of
giveCompliment.
- The value of the variable
myName.
export function giveCompliment(/* TODO parameter(s) go here */) {
// TODO complete this function
}
function main() {
// TODO substitute your own name for "HackYourFuture"
const myName = 'HackYourFuture';
console.log(giveCompliment(myName));
console.log(giveCompliment(myName));
console.log(giveCompliment(myName));
const yourName = 'Amsterdam';
console.log(giveCompliment(yourName));
console.log(giveCompliment(yourName));
console.log(giveCompliment(yourName));
}
// ! Do not change or remove the code below
if (process.env.NODE_ENV !== 'test') {
main();
}
Figure 2. Starter code example: file ex1-giveCompliment.js.
In general, you should only change or add code in the places indicated by the // TODO comments. Once you have implemented what the // TODO comment asks you to do, remove the // TODO comment itself.
You should not delete or rename existing function(s), nor should you change the file names of the starter files. This repository comes with an automated test facility that relies on the presence of these files and functions.
You are allowed to add additional functions and/or global variables (but avoid global variables if you can).
When you are in the process of making changes to a file you will notice a dot or bullet appearing after the file name in the tab of the editor window, as shown in Figure 4 below:
Figure 3. Unsaved changes
This indicates that you have unsaved changes. Once you are done, you can use the File, Save menu commands (or a keyboard shortcut) to save the changes. However, in this repository we have included a setting that automatically saves changes for you whenever you click away from the editor window.
If you are curious about the VSCode settings that we included in this repository, check the file settings.json in the .vscode folder. The setting we mentioned in the previous paragraph is: "files.autoSave": "onFocusChange".
You can learn more about VSCode settings here: User and Workspace Settings.
Prettier VSCode Extension
This is a recommended VSCode extension that we have included in this repository. Prettier is an automatic code formatter to make your code look "pretty". However, it is not just that your code is made pretty, it formats your code into a popular standard that has become well established in the JavaScript community. Other developers, whether trainees, mentors or, later, your colleagues will thank you for using it.
Ensure that you do not install any other code formatter extensions, for example, Beautify, in addition to Prettier. This may cause formatting conflicts.
ESLint VSCode Extension
Another recommended extension is we have included is ESLint. This tool will check your code for coding style errors. Style errors will not necessarily prevent your code from running correctly. However, they indicate that your code does not conform to a preferred coding style. For instance, if you define a variable using the let keyword and you do not reassign that variable elsewhere in your code then ESLint will warn you to replace let with const. In Figure 4 below you can see that the variable name myName has a squiggly colored underline. If you hover your mouse over the variable a pop-up window will appear.
Figure 4. ESLint warnings
You can also inspect the Problems pane or the left hand size of the VSCode status bar to see whether any problems have been detected, as shown in Figure 5.
Figure 5. VSCode Problems Pane
Code Spell Checker
A further extension that we have included is a spell checker that understands code. It particularly understands that variable, property and function names are often multi-word names that use camelCase, PascalCase, snake_case or kebab-case. When it checks for spelling errors it knows how to break up these multi-word names before checking the broken down words against its dictionary. Spelling mistakes are indicated by squiggly underlines and also reported in the Problems pane.
Take pride in the correct spelling in your code. It is a sign of professionalism!
Running the exercises
While working on the exercises you can test-run your code in the usual way, either using the command line (for node-based programs) or by running it in the browser (for browser-based applications). As mentioned earlier, in the JavaScript module you will be working with Node-based programs.
To run the exercise while in VSCode, first open a VSCode Integrated Terminal. You can do so from the VSCode menu, by selecting the Terminal, New Terminal menu commands, or by using the keyboard shortcut as listed in that menu.
Tip: for an overview of the keyboard shortcuts available in VSCode, select the Help, Keyboard Shortcut Reference menu commands. This will open a PDF file in the standard browser, listing all available shortcuts.
The most convenient way to run an exercise from the command line is to use the exercise runner included in this repository. Type the following command to run an exercise this way:
npm start
This will lead you through a series of prompts, similar to as shown below, to select the exercise to run:
? Which module? 1-Javascript
? Which week? Week3
? Which exercise? ex1-giveCompliment
Running exercise, please wait...
You are exciting, HackYourFuture!
You are marvelous, HackYourFuture!
You are awesome, HackYourFuture!
For Node-based programs the console output will be shown in the terminal window. For browser-based application an HTTP server will be started and your web page will opened in the default web browser.