GithubHelp home page GithubHelp logo

drannakurasova / lab-javascript-basic-algorithms Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jorgeberrizbeitia/lab-javascript-basic-algorithms

0.0 0.0 0.0 44 KB

An exercise designed to learn basic JS algorithms (variables, loops, etc...)

JavaScript 77.83% HTML 22.17%

lab-javascript-basic-algorithms's Introduction

logo_ironhack_blue 7

LAB | JS Basic Algorithms

Welcome to your first bootcamp exercise at Ironhack!

The goal of this exercise is to get you familiarized with the primitive data structures in JavaScript, which we just covered in the class. Feel free to reference lesson materials and don't limit yourself but be curious and use Google to explore multiple solutions.

Ready?

qrjeCm

Requirements

  • Fork this repo

  • Clone this repo

  • Type this in the /js/index.js

    console.log("I'm ready!");
  • Save

  • Open index.html with Live Server

  • In the Browser, open the Console Tab

  • If you can see the message you are really ready!

Submission

Upon completion, run the following commands:

$ git add .
$ git commit -m "done"
$ git push origin master

Create Pull Request so your TAs can check up your work.

Instructions

Iteration 1: Names and Input

1.1 Create a variable hacker1 with the driver's name.
1.2 Print "The driver's name is XXXX".
1.3 Create a variable hacker2 with the navigator's name.
1.4 Print "The navigator's name is YYYY".

Iteration 2: Conditionals

2.1. Depending on which name is longer, print:
- The driver has the longest name, it has XX characters. or
- It seems that the navigator has the longest name, it has XX characters. or
- Wow, you both have equally long names, XX characters!.

Iteration 3: Loops

3.1 Print all the characters of the driver's name, separated by a space and in capitals 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 of the strings, print:
- The driver's name goes first.
- Yo, the navigator goes first definitely.
- What?! You both have the same name?

Bonus Time!

Bonus 1:

Go to the lorem ipsum generator 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 appears.

Bonus 2:

Create a new variable phraseToCheck and have it contain some string value. Write a code that will check if the value we assigned to this variable is a 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 the knowledge you currently have and try to come up with a solution by just using the for loop and if-else statements with some break and continue.

Extra Resources

Happy coding! ❤️

FAQs


I am stuck in the exercise and don't know how to solve the problem or where to start.

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

How do you find a length of a string in JavaScript?

To find the length of a string you can use the length property. Here is an example:

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

How do I loop over a string?

Here is an example of using a for loop to loop over a string:

let str = "ironhack";

for (let i = 0; i < str.length; i++) {
  console.log(str[i]);
}

This code will iterate over each character in the str string. The loop will run for as many iterations as there are characters in the string. On each iteration, the loop will log the current character to the console.

Back to top

How do I check if a substring exists in a given string?

You can use the includes() method to check if a substring exists in a given string.

This method returns a boolean value (true or false) indicating whether the string it is called on includes the substring specified as an argument.

Example:

let str = "hello world";

console.log(str.includes("hello"));  // true
console.log(str.includes("world"));  // true
console.log(str.includes("bye"));    // false

You can also use the indexOf() method, which returns the index of the first occurrence of the substring within the string, or -1 if the substring is not found.

Example:

let str = "hello world";

console.log(str.indexOf("h"));      // 0
console.log(str.indexOf("world"));  // 6
console.log(str.indexOf("bye"));    // -1

Back to top

How do I convert a string to capital or lowercase letters?

Uppercase

To convert a string to uppercase letters, use the toUpperCase() method. The method toUpperCase() returns a new string with all the characters in uppercase.

Example:

let str = "ironhack";

console.log(str.toUpperCase());  // "IRONHACK"

Lowercase

To convert a string to all lowercase letters, you can use the toLowerCase() method. This method returns a new string with all the characters in lowercase.

Example:

let str = "IRONHACK";

console.log(str.toLowerCase());  // "ironhack"

It's important to note that methods toUpperCase() and toLowerCase() do not modify the original string. They return a new string that has been converted to the desired case.

Back to top

How do I reverse a string?

You can use a for loop to iterate over the characters of the string and add them to a new string in reverse order.

Example:

let str = "drawer";
let reversed = "";

for (let i = str.length - 1; i >= 0; i--) {
  reversed += str[i];
}

console.log(reversed);  // "reward"

The above example uses a for loop to iterate over the characters of the str string in reverse order, starting at the last character and ending at the first character. On each iteration, it adds the current character to the reversed string.

Back to top

How do I create a multi-line string in JavaScript?

To create a multi-line string in JavaScript, you must use template literals. Template literals are string literals denoted with backticks (`). They allow you to embed expressions inside string values and create strings that span multiple lines.

Example:

let str = `This is an
example of a
multi-line string.`;

console.log(str);

Back to top

I am unable to push changes to the repository. What should I do?

There are a couple of possible reasons why you may be unable to push changes to a Git repository:

  1. You have not committed your changes: Before you can push your changes to the repository, you need to commit them using the git commit command. Make sure you have committed your changes and try pushing again. To do this, run the following terminal commands from the project folder:
git add .
git commit -m "Your commit message"
git push
  1. You do not have permission to push to the repository: If you have cloned the repository directly from the main Ironhack repository without making a Fork first, you do not have write access to the repository. To check which remote repository you have cloned, run the following terminal command from the project folder:
git remote -v

If the link shown is the same as the main Ironhack repository, you will need to fork the repository to your GitHub account first, and then clone your fork to your local machine to be able to push the changes.

Note: You may want to make a copy of the code you have locally, to avoid losing it in the process.

Back to top

lab-javascript-basic-algorithms's People

Contributors

sandrabosk avatar j-1000 avatar tawebbcn avatar marco-ih-bcn avatar jorgeberrizbeitia avatar abernier avatar mjarraya avatar tzikas avatar drannakurasova avatar cule219 avatar lluisarevalo avatar ross-u avatar fontcuberta avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.