![logo_ironhack_blue 7](https://user-images.githubusercontent.com/23629340/40541063-a07a0a8a-601a-11e8-91b5-2f13e4e6b441.png)
# LAB | JS Basic Algorithms
Welcome to your first JavaScript lab at Ironhack!
This exercise aims to familiarize you with the primitive data structures in JavaScript, which we have covered in class. Feel free to reference lesson materials, and don't limit yourself; be curious and use Google to explore multiple solutions.
<br>
![lab-js-basic-algorithms-code-collaboration-gif](https://education-team-2020.s3.eu-west-1.amazonaws.com/web-dev/lab-js-basic-algorithms-code-collaboration-gif.gif)
<br>
<details>
<summary>
<h2>Learning Goals</h2>
</summary>
This exercise allows you to practice and apply the concepts and techniques taught in class.
Upon completion of this exercise, you will be able to:
- Declare variables using `const` and `let` keywords and use them to store values.
- Assign values to variables using assignment operators (`=` , `+=` , `-=` , etc.).
- Use conditional statements (`if`, `else if`, `else`) and logical operators (AND, OR, NOT) to control the flow of the program.
- Access and compare string characters, substrings and length.
- Manipulate strings using basic string methods and proper (`toUpperCase()`, `toLowerCase()`, etc.).
- Compare values using the comparison operators (`<` , `>` , `<=` , `>=` , `===`).
- Use `for` or `while` loops to iterate over strings in normal and reverse order.
<br>
<hr>
</details>
## Introduction
For this **pair-programming** activity, we will use a [REPL](https://en.wikipedia.org/wiki/Read–eval–print_loop). To make things as simple as possible, we are going to use an in-browser JavaScript REPL that is provided by the browser-based IDE, [repl.it](https://replit.com/languages/javascript).
Ready to start?
## Requirements
- Fork this repo
- Clone this repo
- Go to [repl.it](https://repl.it/languages/nodejs) and create an account (or log in if you have one)
- Create a new reply by clicking on <kbd>+ Create Repl</kbd>
- Type this in the *Code Editor* (left panel)
```javascript
console.log("I'm ready!");
```
- Press `run ►`
- If you can see the message in the right side panel, you are really ready!
![lab-js-basic-algorithms-replit-ready](https://education-team-2020.s3.eu-west-1.amazonaws.com/web-dev/lab-js-basic-algorithms-replit-ready.png)
- **When you are done completely, or at any point after the first iteration, copy your code into the `index.js` file and follow the steps for submission.**
## Submission
Upon completion, run the following commands:
```bash
git add .
git commit -m "done"
git push origin master
```
Create a Pull Request so that the TAs can check your work.
*You should make a PR (Pull Request) when you make any significant change. You shouldn't have to wait until you're completely done with this or any other exercise to make the PR. After you do the first PR, any other time you push the changes (following the previous three steps), your change will appear automatically on the PR and your TAs will be able to check it.*
<!-- ## Submission -->
<!-- When you are done and you have checked that everything works fine, click on the **Share** button and copy the link from the *Share Link* field. Send this link to your TAs so they can check up on your work.
![](https://s3-eu-west-1.amazonaws.com/ih-materials/uploads/upload_b2aa98f91affe5d4c5f12f216b069184.png) -->
## Instructions
### Iteration 1: Names and Input
1.1 Create a variable `hacker1` with the driver's name. <br>
1.2 Print `"The driver's name is XXXX"`.<br>
1.3 Create a variable `hacker2` with the navigator's name.<br>
1.4 Print `"The navigator's name is YYYY"`.
### Iteration 2: Conditionals
2.1. Depending on which name [is longer](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/length), print:
<br>
- `The driver has the longest name, it has XX characters.` or <br>
- `It seems that the navigator has the longest name, it has XX characters.` or <br>
- `Wow, you both have equally long names, XX characters!`.
### Iteration 3: Loops
3.1 Print the characters of the driver's name, separated by space, and [in capital letters](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toUpperCase), i.e., `"J O H N"`.
3.2 Print all the characters of the navigator's name in reverse order, i.e., `"nhoJ"`.
3.3 Depending on the [lexicographic order](https://en.wikipedia.org/wiki/Lexicographical_order) of the strings, print: <br>
- `The driver's name goes first.` <br>
- `Yo, the navigator goes first, definitely.` <br>
- `What?! You both have the same name?`
### Bonus Time!
#### Bonus 1:
Go to the [lorem ipsum generator](http://www.lipsum.com/) website and:
- Generate 3 paragraphs. Store the text in a new string variable named `longText`.
- Make your program count the number of words in the string.
- Make your program count the number of times the Latin word [`et`](https://en.wiktionary.org/wiki/et#Latin) appears.
#### Bonus 2:
Create a new variable, `phraseToCheck`, containing some string value. Write a code to check if the value assigned to this variable is a [Palindrome](https://en.wikipedia.org/wiki/Palindrome). Here are some examples of palindromes:
- "A man, a plan, a canal, Panama!"
- "Amor, Roma"
- "race car"
- "stack cats"
- "step on no pets"
- "taco cat"
- "put it up"
- "Was it a car or a cat I saw?" and "No 'x' in Nixon".
__IMPORTANT__: If you use Google to help you to find a solution to this iteration, you might run into some advanced solutions that use string or array methods (such as _join()_, _reverse()_, etc.). However, we want you to apply your current knowledge and try to come up with a solution by just using the `for` loop and `if-else` statements with some `break` and `continue`.
__Happy coding!__ :heart:
## Extra Resources
- [String - MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)
- [if - MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/if...else)
- [while - MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/while)
- [for - MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for)
<br>
## FAQs
<br>
<details>
<summary>I am stuck in the exercise and don't know how to solve the problem or where to start.</summary>
<br>
If you are stuck in your code and don't know how to solve the problem or where to start, you should take a step back and try to form a clear question about the specific issue you are facing. This will help you narrow down the problem and come up with potential solutions.
For example, is it a concept that you don't understand, or are you receiving an error message that you don't know how to fix? It is usually helpful to try to state the problem as clearly as possible, including any error messages you are receiving. This can help you communicate the issue to others and potentially get help from classmates or online resources.
Once you have a clear understanding of the problem, you will be able to start working toward the solution.
[Back to top](#faqs)
</details>
<details>
<summary>How do you find a length of a string in JavaScript?</summary>
<br>
To find the length of a string, you can use the `length` property. Here is an example:
```js
const str = "Hello, world!"";
console.log(str.length); // 13
```
The `length` property returns the number of characters in the string, including spaces and special characters.
[Back to top](#faqs)
</details>
<details>
<summary>How do I loop over a string?</summary>
<br>
Here is an example of using a `for` loop to loop over a string:
```js
let str = "ironhack";
for (let i = 0; i < str.length; i++) {
console.log(str[i]);
}
```
This code will iterate over each