Skip to content

Instantly share code, notes, and snippets.

View sandrabosk's full-sized avatar
👩‍💻
Always a student, never a master. Have to keep moving forward. ~C.Hall

Aleksandra Bošković sandrabosk

👩‍💻
Always a student, never a master. Have to keep moving forward. ~C.Hall
  • Ironhack
View GitHub Profile
// ************************************
// ********* if...else ***************
// ************************************
// IF RETURN IS IN ONE LINE, YOU DON'T HAVE TO USE CURLY BRACES IN IF-ELSE:
const age = 20;
if (age >=21) console.log("You can drink sir or ma'am! 🍻")
else console.log("You can't drink. Sorry! 🥤")
// check-js-conditionals-if.md: https://gist.github.com/sandrabosk/9d0f5b7dc0c2e2d96d1af478621a24cb
// ✅ CHALLENGE 1 ✅
// 1A: if...else - simple solution
if (language === "spanish") console.log(`Hola, Martin`);
else if(language === "french") console.log(`Salut, Martin`);
else if (language === "english") console.log(`Hello, Martin`);
else console.log("I am not sure what are you trying to do, sorry! 🍺");
// WHILE statement creates a loop that executes a specified code as long as the condition evaluates true.
// If you forget to iterate the variable inside a while, you can create an infinite loop.
let i = 0;
while (i <= 100) {
console.log(i);
i++; // this is the same as i = i + 1
}
// do while statement
// check-js-loops.md: https://gist.github.com/sandrabosk/6873d93f293080e896adc84dc212cddf
// 1
for(let i = 1; i<= 50; i++){
if(i % 5 === 0 && i % 7 === 0 ) console.log("ironhack")
else if(i % 5 === 0) console.log("iron")
else if( i % 7 === 0 ) console.log("hack")
else console.log(i);
}

General guidelines for labs/assignments

In this document, you will find all the steps you should follow when working on the labs (in the prework and during the bootcamp).

Step 1: Fork the repository

The majority of time, you will have to start the process with forking. Just a quick reminder on what is the process of forking.

console.log("------------ iteration 1 ------------");
// Iteration 1: Names and Input
// 1.1 Create a variable hacker1 with the driver's name.
let hacker1 = "kevin";
// 1.2 Print "The driver's name is XXXX".
console.log(`hacker1's name is ${hacker1}`);
// 1.3 Create a variable hacker2 with the navigator's name.
// ******************************************************************************************
// PART 1 (DECLARATION, INDEX, ADD, REMOVE)
// ******************************************************************************************
// EXAMPLES OF ARRAYS
const animals = ["dog", "cat", "fish"];
const mixedArr = [3, "fish", true, [], { name: "sandra" }, "", null, ["table", "chair"]];
// arrays are zero indexed
// arrays have the "length" property. it equals (index + 1)
const favorites = ['javascript', 'html', 'css'];
// remove first element
favorites.shift();
console.log(favorites); // => [ 'html', 'css' ]
// remove last element
favorites.pop();
console.log(favorites); // => [ 'html' ]
const fruits = ['apple', 'plum', 'strawberries'];
// 1
for(let i=0; i < fruits.length; i++){
console.log(fruits[i]);
}
// apple
// plum
// strawberries
// ************************************************************************************************
// PART 1: FUNCTION DECLARATION, INVOKE A FUNCTION, NAMING A FUNCTION, PARAMETERS VS. ARGUMENTS, RETURN STATEMENT
// ************************************************************************************************
// Often we need to perform the same or similar action in many places in our application
// functions can be defined as reusable pieces of code that perform specific actions
// Functions are the main “building blocks” of any program.
// They allow the code to be reused many times without repetition. They keep our code DRY (Don’t Repeat Yourself).
// create => function declaration