- Practice the concepts
- JavaScript exercises
- Code along
- PROJECT: Hack Your Repo II
Let's start this week off with some interactive exercises! Visit the following link to get started:
Inside of your
JavaScript3
fork and inside of theWeek2
folder, create a folder calledhomework
. Inside of that folder, create a folder calledjs-exercises
. For all the following exercises create a new.js
file in that folder (3 files in total). Make sure the name of each file reflects its content: for example, the filename for exercise one could begetName.js
.
Exercise 1: John who?
Take a look at the following function (and try it out in your console):
const getAnonName = (firstName, callback) => {
setTimeout(() => {
if (!firstName)
return callback(new Error("You didn't pass in a first name!"));
const fullName = `${firstName} Doe`;
return callback(fullName);
}, 2000);
};
getAnonName('John', console.log);
Rewrite this function, but replace the callback syntax with the Promise syntax:
- Have the
getAnonName
function return anew Promise
that uses thefirstName
parameter - If the Promise
resolves
, pass the full name as an argument to resolve with - If the Promise
rejects
, pass an error as the argument to reject with: "You didn't pass in a first name!"
Exercise 2: Is it bigger than 10?
Write a function called checkDoubleDigits
that:
- Takes 1 argument: a number
- Returns a
new Promise
- If the number is bigger than 10, resolve with the string: "The number is bigger than 10!"
- If the number is smaller than 10, reject with the error: "Error! The number is smaller than 10..."
Exercise 3: Gotta catch 'em all
Inside of your
homework
folder, create another folder calledpokemon-app
. There, create anindex.html
andscript.js
file
Let's catch all original 151 Pokemon in our own little web application! Here's an example of what you'll be building for this exercise:
In this exercise you're going to do several things:
- Create and append DOM elements using JavaScript only
- Fetch data twice from a public API PokeAPI
- Display the results in the DOM.
Here are the requirements:
- Create 3 functions:
fetchData
,addPokemonToDOM
andmain
- The
main
function executes the other functions and contains all the variables - In the
fetchData
function, make use offetch
and its Promise syntax in order to get the data from the public API - Execute the
main
function when the window has finished loading
In the following "code along" you'll be building a complete Weather App that makes use of the Darksky API.
Enjoy!
This week we'll continue building on our work from last week. Make sure to navigate to the
hackyourrepo-app
folder and start based on the code you wrote!
This week we'll do a couple of things:
- We'll remove our HTML elements and remake them using JavaScript only!
- We'll replace our placeholder data with real data from the GitHub API
- We'll display this data in a separate column of the user interface
On the surface, it'll look exactly the same. But functionally, it'll based around JavaScript only!
Here are the requirements:
- Remove the HTML elements you created last week, and only keep the
<script>
tag (you can keep the styling) - Recreate all the HTML elements using JavaScript
- Populate the
<select>
with options. Use the data fetched from the GitHub API, using this URL:
const url = 'https://api.github.com/orgs/HackYourFuture/repos?per_page=100';
- When a user changes the option in the
<select>
tag, listen to that "change" event and make an HTTP Request to the GitHub API to get repository-specific data. Read the documentation to find out which URL you need to use: GitHub API Documentation - When the repository-specific has been fetched, populate the right columns: contributors and repository details.
- If there's an error in the HTTP Request, display the following:
- Create a
main
function that will execute all of your functions only when the window has fully loaded
The end result should be similar to this in styling, but exactly in functionality:
Click on the image to open up the demo of the application!
Good luck!
After you've finished your todo list it's time to show us what you got! The homework that needs to be submitted is the following:
- PROJECT: HackYourRepo II
Upload your homework to your forked JavaScript3 repository in GitHub. Make a pull request to your teacher's repository.
Forgotten how to upload your homework? Go through the guide to learn how to do this again.
Deadline Saturday 23.59 CET