This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Chaining Multiple Promises | |
firstPromiseFunction() | |
.then((firstResolveVal) => { | |
return secondPromiseFunction(firstResolveVal); | |
}) | |
.then((secondResolveVal) => { | |
console.log(secondResolveVal); | |
}); | |
-------------------- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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 | |
` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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: | |
` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
**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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### **WEB DEVELOPMENT** | |
# **Project: Artusi** | |
<br> | |
# **Tasks** | |
<br> | |
#### **1. Print the working directory** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### **SOFTWARE ENGINEERING FOUNDATIONS** | |
# **Project: Athletica** | |
<br> | |
# **Tasks** | |
#### **1. Print the working directory** | |
``` | |
$ pwd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
LEARN EXPRESS ROUTES | |
Setting Status Codes | |
Express allows us to set the status code on responses before they are sent. Response codes provide information to clients about how their requests were handled. | |
Until now, we have been allowing the Express server to set status codes for us. For example, any res.send() has by default sent a 200 OK status code. | |
The res object has a .status() method to allow us to set the status code, and other methods like .send() can be chained from it. | |
const monsterStoreInventory = { fenrirs: 4, banshees: 1, jerseyDevils: 4, krakens: 3 }; | |
app.get('/monsters-inventory/:name', (req, res, next) => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<style> | |
body { | |
margin: 0; | |
min-width: 250px; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |
OlderNewer