/lab-javascript-basic-algorithms

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

Primary LanguageJavaScript

Ironhack Logo

JS | Basic Algorithms

Welcome to your first bootcamp exercise at IronHack!

The goal of this exercise is to get you acquainted with the different control structures we have in JavaScript.

Ready?

Introduction

For this Pair-Programming activity we are going to use a REPL. You can fine a REPL that runs in the browser for programming languages as JavaScript in repl.it

We could also type JavaScript code in an editor, and then execute it to see the results in the REPL.

Ready to start?

Requirements

  • Go to repl.it and create an account (or login if you have one)

  • Open a new repl.it and make sure the language is ==JavaScript==

  • Type this in the ==Code Editor== (left panel)

    console.log("I'm Ready!");
  • Press run ►

  • If you can see the message on the JavaScript REPL, you're ready!!

Submission

When you are done and you have checked that everything works fine, go to https://gist.github.com/, create a new secret gist and send it to your Instructor.

Remember: Remember to add the extension of the file fileName.js in the "Filename including extension" input box so you can enjoy syntax highlighting in your gist

Exercise

Names and Input

  1. Create a variable hacker1 with the driver's name

  2. Print "The driver's name is XXXX"

  3. Create a variable hacker2 and ask the user for the navigator's name

  4. Print "The navigator's name is YYYY"

Conditionals

  1. Depending on which name is longer, print:
    • The Driver has the longest name, it has XX characters or
    • Yo, navigator got the longest name, it has XX characters or
    • wow, you both got equally long names, XX characters!!

Loops

  1. Print all the characters of the driver's name, separated by a space and in capitals ie. "J O H N"

  2. Print all the characters of the navigator's name, in reverse order. ie. "nhoJ"

  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 got the same name?

Bonus Time!

  1. Ask the user for a new string and check if it's a Palindrome. 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".
  2. Go to lorem ipsum generator and:

  • Generate 3 parragraphs. Store the text in a String
  • Make your program count the number of words in the string
  • Make your program count the number of times the latin word etappears

Extra Resources