Skip to content

Instantly share code, notes, and snippets.

@Nalini1998
Nalini1998 / Chaining Multiple Promises
Last active April 19, 2023 21:18
JAVASCRIPT PROMISES: One common pattern we’ll see with asynchronous programming is multiple operations which depend on each other to execute or that must be executed in a certain order. We might make one request to a database and use the data returned to us to make another request and so on! Let’s illustrate this with another cleaning example, w…
Chaining Multiple Promises
firstPromiseFunction()
.then((firstResolveVal) => {
return secondPromiseFunction(firstResolveVal);
})
.then((secondResolveVal) => {
console.log(secondResolveVal);
});
--------------------
@Nalini1998
Nalini1998 / Build a Library
Created April 19, 2023 21:14
Build a Library Project: Books-‘N-Stuff carries three different types of media: books, CDs, and movies. In this project you will create a parent class named Media with three subclasses: Book, Movie, and CD.
// Created by Nalini Vo from Vietnam
// Requires:
**1. Book**
**Properties**: Author (string), title (string), pages (number), isCheckedOut (boolean, initially false), and ratings (array, initially empty).
**Getters**: All properties have a getter
**Methods**: .getAverageRating(), .toggleCheckOutStatus(), and .addRating()
**2. Movie**
**Properties**: Director (string), title (string), runTime (number), isCheckedOut (boolean, initially false), and ratings (array, initially empty)
**Getters**: All properties have a getter
**Methods**: .getAverageRating(), .toggleCheckOutStatus(), and .addRating()
@Nalini1998
Nalini1998 / Install Mocha I Part 1
Last active April 20, 2023 22:13
Install Mocha I Part 1
[How to install Mocha Part 1?](https://www.codecademy.com/journeys/full-stack-engineer/paths/fscj-22-front-end-development/tracks/fscj-22-javascript-testing/modules/wdcp-22-write-good-tests-with-mocha-764e85ca-0abf-4da9-91a2-43f8d593eab8/lessons/automate-organize-tests/exercises/install-mocha-i)
1. Before writing any tests you’ll need to use Node.js and npm to set up a JavaScript project and install Mocha;
2. Node allows you to run JavaScript in the terminaL;
3. `npm` is a **Node tool** that allows you to download packages from the web, and manage them in a JavaScript project;
4. Mocha is one of those packages and is used to test other JavaScript code;
5. A JavaScript project is a directory of files. The following command creates a file package.json that can be used to manage packages for the project.
`
$ npm init
`
@Nalini1998
Nalini1998 / Install Mocha Part II
Created April 20, 2023 18:50
Install Mocha Part II
#How to install Mocha Part II?
1. After installing Mocha as a dependency we can run it in two ways.
+ The first (and more tedious) method is to call it directly from node_modules:
`
$ ./node_modules/mocha/bin/mocha
`
+ The second (and recommended) method is to add a script to package.json. In the scripts object in package.json, set the value of "test" to mocha. It should look like this:
`
@Nalini1998
Nalini1998 / Setup, Exercise, and Verify
Created April 20, 2023 22:10
AUTOMATE AND ORGANIZE TESTS Setup, Exercise, and Verify In this exercise you will be separating a test into setup, exercise, and verify phases. This distinct and well-defined separation of steps makes your test more reliable, maintainable, and expressive. The phases are defined as follows: Setup - create objects, variables, and set conditions th…
**Setup, Exercise, and Verify**
- In this exercise you will be separating a test into setup, exercise, and verify phases. This distinct and well-defined separation of steps makes your test more reliable, maintainable, and expressive.
- The phases are defined as follows:
+ Setup - create objects, variables, and set conditions that your test depends on;
+ Exercise - execute the functionality you are testing;
+ Verify - check your expectations against the result of the exercise phase. You can use the assert library here.
@Nalini1998
Nalini1998 / Project: Artusi
Created July 19, 2023 09:26
Let's use commands to manipulate the files and directories of Artusi, an arts supply Store
### **WEB DEVELOPMENT**
# **Project: Artusi**
<br>
# **Tasks**
<br>
#### **1. Print the working directory**
@Nalini1998
Nalini1998 / Athletica Project
Created July 19, 2023 09:27
In this Project, we’ll use the commands we've learned to redirect files in Athletica, a sporting events directory.
### **SOFTWARE ENGINEERING FOUNDATIONS**
# **Project: Athletica**
<br>
# **Tasks**
#### **1. Print the working directory**
```
$ pwd
@Nalini1998
Nalini1998 / index.html
Created July 28, 2023 16:38
To do App
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
body {
margin: 0;
min-width: 250px;
}
@Nalini1998
Nalini1998 / forEach()
Created January 16, 2024 07:42
The forEach() method
The forEach() method is used to loop through all elements of an array and calls a function (callback function) for each element in the array. The callback function has access to the current element, index, and the entire array on every loop.
```
// Syntax
myArray.forEach(callbackFn)
myArray.forEach(function(element, index, array){ /* ... */ })
```
For example:
@Nalini1998
Nalini1998 / map()
Created January 16, 2024 07:48
The map() method
The map() method is used to iterate over an array and modify its elements using a callback function. This callback function will run on each array element and return a new array of modified elements.
```
// Syntax
myArray.map(callbackFn)
myArray.map(function(element, index, array){ /* ... */ })
```
For example:
```