pomSense / coding-playbook

A set of assignments to help you learn node.js and TypeScript

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

coding-playbook

A set of assignments to help you learn node.js and TypeScript

Learn to Code

Assignment 1 - Local Development Environment & Git

  1. Set up Git: Follow these instructions to setup your SSH keys. This assumes you already have a GitHub account.
  • If this is your first time learning to code and you have no clue about Git or GitHub, then you can start with this video
  • Here are some basic commands for Git
  1. Download VSCode and install
  2. Follow this setup
  • Note, if you're using Windows, there may be some steps that are different (i.e Step 2)
  1. Change your VSCode theme. Instructions are here

Important: If you get stuck on any of the steps, you are encouraged to use chatGPT or search google. One of the most important skills for any developer is the ability to self-sufficiently figure out how to do something whether via searching google or reading documentation.

Tasks

  • [ ]Try to clone this repo to your local machine. If you get stuck, ask for help in chatGPT.
  • [ ]Create a new branch with your name, and push your changes to that branch. Then open a PR to @param for review.

Assignment 2 - Learn Javascript

Codecademy is what we will use to learn the fundamentals of Javascript and TypeScript.

One of the most important things is the fundamentals. This is why we spend so much time on them. Make sure you really spend the time to understand the fundamentals or your entire learning journey will be impacted. Without a good understanding of the fundamentals, you will struggle in later phases and on your journey.

Tasks

  • Create a Repo on your local machine called 'learning-code'. Also create the repository on GitHub and link the two together. You will be using this repo to save all your code for this course. It is good practice to run the code you will learn from Codecademy in your local machine. Although the practice lessons in codecademy have a built-in editor, it is good practice to run the code in your local machine. Each time you are done with your lesson, commit and push your code.

  • Complete the Learn Javascript course in Codecademy. Make sure to do all of the quizes and projects.

  • Complete the Learn Typescript course in Codecademy.

Assignment 3 - Intermediate JavaScript

We will repeat what we did in Assignment 2, but for the Intermediate JavaScript course.

Tasks

  • Complete the Intermediate JavaScript course in Codecademy. Make sure to do all of the quizes and projects.
  • Make sure you continue to push your code to your repo on GitHub. This is important for you to get used to doing. If you get stuck, ask for help in chatGPT.

Assignment 4 - Deep dive

Now we will dive deeper into JavaScript. and complete more advanced courses in Codecademy. One of the most important things is the fundamentals. This is why we spend so much time on them. Make sure you really spend the time to understand the fundamentals or your entire learning journey will be impacted. Without a good understanding of the fundamentals, you will struggle in later phases and on your journey.

Tasks

Assignment 5 - Typescript

We will repeat what we did in Assignments 2 and 3, but we will learn TypeScript. Don't worry, TypeScript is just a superset of JavaScript, so it is very similar to JavaScript. Think of TypeScript as a more strict version of JavaScript, or like a "Spell-check" for JavaScript.

Tasks

Assignment 6

Readings:

Videos:

Use this cheat-sheet for Git:

Pre-requisite:

Task 1

  1. Pull this repo to your local, use the Git cheat-sheet above.
  2. Create a separate branch to save your work on
  3. Once you are on your branch, create a directory with your name, and we will save your files in there

Task 2

Write a function sum that takes an array of numbers and returns the sum of these numbers. Write a function mean that takes an array of numbers and returns the average of these numbers. The mean function should use the sum function.

Test your functions in VSCode Terminal use node {filename}.js

Task 3

Write a function greet having one parameter and returning 'Hello !'.

Example: greet('Ada') should return 'Hello Ada!' and greet('Grace') should return 'Hello Grace!'.

Then, write a function logger that takes a string and prints to the console that string.

Next, create a function greetAndLog that takes in a name string, and uses both the greet and logger functions to log the output to the console.

Task 4

Mini Linter Project

In this project, you will use what you know about iterating over arrays to improve the quality of a paragraph and gather some information about that paragraph.

This is the same type of work that word processing software does. Additionally, you may have heard of linting, a process by which text is evaluated and improved by an application. In this project, you will create a miniature version of a linter using array methods that you have learned.

  let story = 'Last weekend, I took literally the most beautiful bike ride of my life. The route is called "The 9W to Nyack" and it actually stretches all the way from Riverside Park in Manhattan to South Nyack, New Jersey. It\'s really an adventure from beginning to end! It is a 48 mile loop and it basically took me an entire day. I stopped at Riverbank State Park to take some extremely artsy photos. It was a short stop, though, because I had a really long way left to go. After a quick photo op at the very popular Little Red Lighthouse, I began my trek across the George Washington Bridge into New Jersey.  The GW is actually very long - 4,760 feet! I was already very tired by the time I got to the other side.  An hour later, I reached Greenbrook Nature Sanctuary, an extremely beautiful park along the coast of the Hudson.  Something that was very surprising to me was that near the end of the route you actually cross back into New York! At this point, you are very close to the end.';

let overusedWords = ['really', 'very', 'basically'];

let unnecessaryWords = ['extremely', 'literally', 'actually' ];
  1. In the code editor, there is a string called story. We want to gather some information about the individual words and sentences in the string. Let’s split the string into individual words and save them in a new array called storyWords.
  2. Log how many words there are in this story to the console.
  3. There is an array of words that are unnecessary. Iterate over your array to filter out these words. Save the remaining words in an array called betterWords. There are several ways that you could achieve this.
  4. There is an array of words called overusedWords. These are words overused in this story. You want to let the user of your program know how many times they have used these overused words. There are two ways to achieve this. Try it on your own first. If you need help, consult the hint.
  5. Now, count how many sentences are in the paragraph. This may seem tricky, but remember that all of the sentences in this paragraph end with a period (.) or an exclamation mark (!). You could iterate over the array and add 1 to a sentence counter variable for each word that has a period or exclamation mark as its final character.
  6. Log these items to the console: 1. The word count, 2. The sentence count, 3. The number of times each overused word appears. You could choose to simply log them one by one or, for a challenge, create a function that logs all of them with some formatting.
  7. Now, log the betterWords array to the console as a single string.
  8. Congratulations! You’ve improved the original paragraph and given the user some important information about his or her work. Think about ways in which you can extend this project, potentially by using other JavaScript knowledge you have. Here are some ideas:
    • For the overused words, remove it every other time it appears.
    • Write a function that finds the word that appears the greatest number of times.
    • Replaced overused words with something else.

Task 5

Submit your changes on your branch, and push the branch to GitHub. Then open a PR request to @param for reivew.

Assignment 7 - Promises

Pre-Requisities from Codecademy:

  • Functions
  • Objects
  • Arrays
  • Loops
  • Modules
  • Promises
  • Async Await

Readings/Videos:

1. Load Faker part 1 - I hate bugs🐞!!

Read about the Faker npm package and install it as a dependency for this project. https://github.com/Marak/Faker.js#readme

Here is a Load faker function that is created for you to use when needing to create loads. First, install faker.js npm package in your folder, and create a faker.js file with the following function code:

const faker = require('faker')

function createLoad() {
  const stopStatus = {arrived: 'arrived', departed: 'departed', enroute: 'enroute'}
  const accountIds = [
    'sdfs973-233hjkh-dfg89-re9f8',
    'sd4f65-cs7h9f-dfg565-d645dfg',
    'sdfs973-233hjkh-dfg89-re9f8',
    'fgh8k-djj52k-osxm4-ne73',
    'j73sg-653nd3-nd36d-fdg357'
  ]
  const userIds = [
    '326ffkh-233hjkh-whhb-bfzm5',
    'sad5ety-0ebw5bf-234dsf-fdg357',
    '14dg-fdg357-0ebw5bf-fgh8k',
    'fgh8k-gd12-osxm4-gd45ag',
    'sdfs973-653nd3-6hgad6-fdg357'
  ]
  const role = ['carrierRep', 'accountRep', 'driver']
  const user = {
    id: faker.random.arrayElement(userIds),
    username: '',
    password: faker.internet.password(), // password
    firstName: faker.name.firstName(),
    lastName: faker.name.lastName(),
    email: faker.internet.email(),
    role: faker.random.arrayElement(role),
    accountId: faker.random.arrayElement(accountIds),
    passwordResetDate: new Date()
  }

  return {
    id: faker.random.uuid(),
    company: faker.company.companyName(),
    creationDate: new Date(),
    accountId: faker.random.arrayElement(acountIds),
    user: user(),
    userId: user.Id,
    status: faker.random.arrayElement(status)
  }
}

Run this function inside of faker.js file and resolve any bugs that might be there. Once done, in the comments at bottom of file, write out all the bugs that you fixed.

2. Load Faker part 2

Now, export this function (export default) so it can be used in your main assignment file. To test if you are exporting and importing correctly, create another file called assignmen5.js, and import the exported function at the top of the new file.

Then console.log the function result to see if you are exporting and importing correctly.

3. Write an async function and get the result

In assignment5.js, write a async function that's job is to return a promise with an array of 1000 random loads.

Then, find a way to console.log the 10th element of the array of loads. Here you will learn how to get a promise from an async function, and then handle that promise somewhere else to get the data you need.

4. Time your function

Find out how fast your function is running and print the results here. Try running with 10000 loads to get a sense of how long it is taking to run.

5. Multiple ways to write

Here we will test your ability on loops by writing function that loops over an array of 10000 random loads and returns an array of loads that match the accountId of 'sdfs973-233hjkh-dfg89-re9f8'.

Write an async function for each of the following methods:

  • for loop
  • forEach
  • map

Time each of the functions and observe which one is fastest. When you are running the function, once you get the result, console.log the 10th element.

NOTE: These functions aren't required to be async but we are doing it that way for sake of learning. If you want, try making them not-async functions and compare the time it takes to execute the function versus the async version.

6. Get all loads

We are going to get all loads that match certain criteria.

  • Create one async function that loops over an array of loads and gets all loads where the user is a driver
  • Create one async function that loops over an array of loads and gets all loads where the user is a carrierRep and status is arrived
  • Create one async function that loops over an array of loads and gets all loads where the user is not a driver or carrierRep and status is arrived. But don't include loads where the accountId is 'sdfs973-233hjkh-dfg89-re9f8' and user's firstName is larger than 5 characters.
  • Create one controller function that creates an array of 10,000 loads, and calls all of the three above functions with that array. Then print the 1st load in each of the functions' results. Time how long it takes each function to run and also for the controller to run.
  • Now duplicate the controller function, but this time we will run it differently. Read on running things aysynchronously here.
    • Find the fastest possible way to run this asynchronously and compare the difference in time it takes for the synchronous looping.

Assignment 8 - Refactor and Documentation

Task 1:

  • Refactor your code to be completely functional. Every function should only do 1 thing

Task 2:

  • At the beginning of each function, write comments using block comment syntax. This means, starting your comments with /** and it will auto-generate a block right before your comments.
  • See example here on how to write comments: https://jsdoc.app/tags-returns.html
  • Each param should explain what it is and its type, and what the function returns. Also one line on what the function does. See example from previous link.

Assignment 9 - Typescript and TypeDocs

Watch:

  1. Video 1 - Typescript - The Basics
  2. Video 2 - Interfaces vs Types
  3. Learn how to run typescript code

Task 1

Complete the TypeScript Course in Codecademy.

Task 2

Convert your code to TypeScript following instructions here.

Task 3

Run your code in TypeScript. If you don't know how, Google how to run typescript code ;)

Task 4:

  • Create documentation for your code using https://typedoc.org/
  • Install typedoc as a dev dependency (that means use npm i --save-dev or pm i -D for short when installing
  • Read documentation on typedoc on how to use it. Practice reading documentation to figure out how to use a package.

Assignment 10 - NodeJS

Readings:

Task - Mosh course on NodeJS

Complete this: https://codewithmosh.com/courses/enrolled/293204

Assignment 11 - Twilio

For this assignment, we will use Node.js to send and receive SMS and MMS Text Messages

Tasks

Tasks to be completed:

  • Create a directory: src/{name}/twilio
  • Finisih this quickstart: https://www.twilio.com/docs/sms/quickstart/node
  • Set up your development environment to send and receive messages
  • Set up an express server (API)
  • Send SMS from the App
  • Receive SMS from the App
  • When an SMS is received, respond via the App with "Hey there!"
  • When an SMS is received, check in the UAT DB to see if that phone number exisits in the device table,
  • If it exisits, respond with "Welcome back!", if it doesn't respond with "Hmmm, did you send this to a wrong number?"
  • Now for the scenario where the device exists, check if we have the name property, then change the message to: "Welcome back {name}!"

Reply to incoming messages with an SMS

Assignment 11.5 - Twilio on steriods!!

Well done! If you made it this far, you should pat yourself on the back. This is a big accomplishment.

Let's make things a little more difficult, but more fun at the same time!

Tasks:

  • Create a directory lt-driver-bot-api and pull the repo onto your local
  • Review the code for incomingMessage, and see how the logic is

Assignment 12 - Final assignment: Jest

Create a unit test for the new Chaine project. You will write your first integration test for

  • should change password if email, code and password is valid

Task 1

  • Pull the lt-driver-mobile-app-api repo on your local
  • Get the server to run properly

Task 2

  • Get the test command in package.json to run correctly

Task 3

  • Review the tests written for different files
  • Identify up to 3 scenarios that test coverage is pending
  • Write Jest Integration Tests for scenarios that are pending coverage. Remember to understand what an integration test is first.

About

A set of assignments to help you learn node.js and TypeScript