emsesc / chloerulezzzz

0 stars 0 forks source link

[TOP SECRET] Please open #8

Open ghost opened 3 years ago

ghost commented 3 years ago

Week 1 Step 8 ⬤⬤⬤⬤⬤⬤⬤⬤◯ | 🕐 Estimated completion: 5-15 minutes

[TOP SECRET] Morse Code Converter

Dwight being a spy

Welcome agent! You have made it this far so we know we can trust you. BitProject is working in an undercover operation, and we need a new way to communicate.

✅ Tasks:

:exclamation: Do not merge the branch!!

1: Installing Packages

Create a new HTTP trigger function in your Azure portal along with the Function App. Navigate to your Function App. This is not the function code, but the actual app service resource.

We will be using the morse-code-converter npm package.

:question: Why do we need these "packages" and what are they?
Packages are awesome! They're chunks of publicly available code that someone else has written to help make coding easier for everyone else. These packages reusable code that increases functionality in your code. Before the Azure Function can run the code we will write, we have to install all the necessary package dependencies. These packages contain **code that we will "depend on" in the application**; we have to install them in the console using `npm install`. [What is a package?](https://www.w3schools.com/nodejs/nodejs_npm.asp) [What is the morse-code-converter package?](https://www.npmjs.com/package/morse-code-converter)

:question: How do I install the package?
In the left tab, scroll down to Console: ![console](https://user-images.githubusercontent.com/52464195/93178238-cf5c4e00-f6e8-11ea-90ab-c42f746cf04e.png) Enter these commands in order: ```sh npm init -y npm install morse-code-converter ```

:exclamation: Woah! What just happened when the package was installed?
The first command created a **package.json** file to store your dependencies and essentially keeps track of what packages your application needs. You can find this file by going into the left menu and clicking on "App Files". Screen Shot 2021-04-26 at 3 15 21 AM The next one actually installs the necessary packages with code, `morse-code-converter`. *Note: If you get red text like `WARN`, you can ignore it.* Screen Shot 2021-04-26 at 3 12 43 AM

:books: Reminder: don't forget to import your package! const morse = require("morse-code-converter");

:bulb: Make sure your parameter is named plaintext

2: Using morse-code-converter

:question: How do I receive the English as a parameter?
[Query parameters](https://rapidapi.com/blog/api-glossary/parameters/query/) can be accessed from the `req` object in the input of the `module.exports` function. > :bulb: Since ours is named `plaintext`, we can access it with `req.query.plaintext`. **How would I send the English?** [place your function url here]&plaintext=[insert the English]

:question: How do I use the Morse Code package?
**Tip**: Try reading the [documentation](https://www.npmjs.com/package/morse-code-converter) first. ```js const morse = require("morse-code-converter"); const code = morse.textToMorse('Hey how are you?'); // .... . -.-- .... --- .-- .- .-. . -.-- --- ..- ..-.. const text = morse.morseToText(code); // HEY HOW ARE YOU? ```

:bulb: Be sure to return the code in the body of the response!

:question: Um. Body?
**Tip**: `context.res` is the object you use to return a response to the user. ```js context.res = { body: [insert your encoded English here] }; ```

:exclamation: Don't forget to git pull before making any changes to your local repo!!

Remember: we test your Morse Code function everytime you commit!