diff --git a/01-Fundamentals-Part-1/starter/index.html b/01-Fundamentals-Part-1/starter/index.html index 59529c7923..d3c6979eed 100755 --- a/01-Fundamentals-Part-1/starter/index.html +++ b/01-Fundamentals-Part-1/starter/index.html @@ -1,29 +1,37 @@ - - - - - JavaScript Fundamentals – Part 1 - - - -

JavaScript Fundamentals – Part 1

- - + + + + + + JavaScript Fundamentals - Part 1 + + + + + + +

JavaScript Fundamentals - Part 1

+ + + + + \ No newline at end of file diff --git a/01-Fundamentals-Part-1/starter/script.js b/01-Fundamentals-Part-1/starter/script.js new file mode 100644 index 0000000000..fd42dffea0 --- /dev/null +++ b/01-Fundamentals-Part-1/starter/script.js @@ -0,0 +1,4 @@ +const age = 23; +const drink = age >= 18 ? "wine" : "water"; + +console.log(`I like to drink ${age >= 18 ? "wine" : "water"}`); diff --git a/02-Fundamentals-Part-2/final/index.html b/02-Fundamentals-Part-2/final/index.html index ee4909e282..5b4e7e726f 100755 --- a/02-Fundamentals-Part-2/final/index.html +++ b/02-Fundamentals-Part-2/final/index.html @@ -1,30 +1,30 @@ - - - - - JavaScript Fundamentals – Part 2 - - - -

JavaScript Fundamentals – Part 2

- - + + + + + JavaScript Fundamentals – Part 2 + + + +

JavaScript Fundamentals – Part 2

+ + diff --git a/02-Fundamentals-Part-2/final/script.js b/02-Fundamentals-Part-2/final/script.js index 8cee2087f7..bed4b98c68 100755 --- a/02-Fundamentals-Part-2/final/script.js +++ b/02-Fundamentals-Part-2/final/script.js @@ -1,4 +1,4 @@ -'use strict'; +"use strict"; /* /////////////////////////////////////// diff --git a/02-Fundamentals-Part-2/starter/script.js b/02-Fundamentals-Part-2/starter/script.js index e69de29bb2..f4b31efcdb 100755 --- a/02-Fundamentals-Part-2/starter/script.js +++ b/02-Fundamentals-Part-2/starter/script.js @@ -0,0 +1,7 @@ +"use strict"; + +let rep = 1; //should create it outside and before the loop +while (rep <= 10) { + console.log(rep); + rep++; +} diff --git a/03-Developer-Skills/starter/script.js b/03-Developer-Skills/starter/script.js index 939b2a2446..4952f940a6 100644 --- a/03-Developer-Skills/starter/script.js +++ b/03-Developer-Skills/starter/script.js @@ -1,3 +1,2 @@ // Remember, we're gonna use strict mode in all scripts now! -'use strict'; - +"use strict"; diff --git a/NOTES b/NOTES new file mode 100644 index 0000000000..5288e85905 --- /dev/null +++ b/NOTES @@ -0,0 +1,243 @@ +console.log(typeof true); +// Gives the type of a variable + + +firstname = "Bogdan"; +const jonasnew = `I'm ${firstname}, i am 20 yo`; +// Use `` saves time, no need to use operators for strings, and dont bother with spaces. + +\n\ to skip to the next line or just use `` and enter + + +/* 5 falsy values : 0, '', undefined, null, NaN +(false) all of them become false when converted to boolean. Any other value will be ocnverted to true. +For example +const money = 0 +if (money){ + console.log('hello') +} else { + console.log('this will be console logged since money = 0 = false') +} +*/ + +/* loose equality operator '18' == 18 will return true, while '18' === 18 returns false +const favourite = Number(prompt("what's your fav number ? ")); + +console.log(favourite); +console.log(typeof favourite); + +if (favourite === 23) { + console.log("cool 23 is great"); +} + + +!== operator for not equal + */ + + +//Logic operators : +&& for AND +|| for OR +! for Opposit + + +//THE SWITCH STATEMENT, allows to write faster than if, else if, else... + +const day = 'monday' + +switch(day){ + case 'monday': + console.log('this will print out if monday, use break otherwise it will just go on and on') + break + case 'tuesday': + case 'wednesday': + console.log('this will printout if tuesday or wednesday') + case 'thursday....' +} + +//CONDITIONAL (TERNARY) OPERATOR +const age = 23 +const drink = age >= 18 ? 'wine' : 'water' + +console.log(I like to drink ${age >= 18 ? 'wine' : 'water'}) + + +// to avoid hidden erors write this on the first line of every js file +'use strict' + + + +//////FUNCTIONS FUNCTIONS FUNCTIONS FUNCTIONS FUNCTIONS FUNCTIONS FUNCTIONS FUNCTIONS////// + +//CREATE A FUNCTION (this way you can call this function even before declaring it) +function logger(name) { + return `Hello ${name}`; +} +const sentence = logger("Bogdan"); +console.log(sentence); + +//FUNCTION EXPRESSION (need to store it in variable since it produce a value) (cannont call it before defining it) +const calcAge = function (birthyear) { + return 2037 - birthyear; +} +const age = calcAge(1991); +console.log(age); + +//ARROW FUNCTION (also expression function), (use parantheses for multiple parameters) +const calcage2 = birthyear => 2037 - birthyear; +const age2 = calcage2(1991) +console.log(age2) + +// 3 types tgether + + +function calcAge(birthyear){ + return 2037 - birthyear; +} + + + const calcAge = function (birthyear){ + return 2037 - birthyear; + } + + + const calcAge = birthyear => 2037 - birthyear; + + + +////// ARRAYS ARRAYS ARRAYS ARRAYS ARRAYS ARRAYS ARRAYS ARRAYS ARRAYS ARRAYS ARRAYS ARRAYS ////// + +const numbers = [1,2,3,4] + +const years = new Array(1,2,3,4); //creation of new array using function + +const length = years.length // get the length of an array + +//ARRAY METHODS + +years.push(2024) // adds an element to the array +years.unshift(1995) // adds an element at the beggining of the array +years.pop() // removes the last element of an array +years.shift() // removes the first element of an array + +years.indexOf(2024) // returns the index of the searched element, if not, returns -1 + +years.includes(2024) // returns a bollean value + + +//////OBJECTS OBJECTS OBJECTS OBJECTS OBJECTS OBJECTS OBJECTS OBJECTS OBJECTS OBJECTS ////// + +const jonas = { + firstname : 'jonas' + lastname : 'shemd' + age : 2037-1991 + job : 'teacher' +} + +jonas.lastname //returns shemd, the value of the key +jonas['lastname'] // returns shemd, but to be used in functions since you can insert into [ ] for example : +const nameKey = 'Name' +console.log(jonas['first'+nameKey]) + +jonas.location = 'Portugal'; // adding new keys/values to the object +jonas['location2'] = 'France'; // adding new keys/values to the object + + + +const jonas = { + firstname : 'Jonas', + lastname : 'Shmed', + calcAge : function (birthyear){ + return 2037-birthyear + } +}; +console.log(jonas.calcAge(1991)); // dot method +console.log(jonas["calcAge"](1991)); //bracket method + +//in the next example we use this that references the object itself +const jonas = { + firstname : 'Jonas', + lastname : 'Shmed', + birthyear : '1991', + calcAge : function (){ + console.log(this) // just to see the objec, no need to write + return 2037 - this.birthyear //this applies to jonas object === this + } +}; +console.log(jonas.calcAge()); + +//here we will store the result of a function inside of a keyword age +const jonas = { + firstname : 'Jonas', + lastname : 'Shmed', + birthyear : '1991', + + calcAge : function (){ // function that calculates the age + + this.age = 2037 - this.birthyear //calculating the age and storing it in this.age + + return this.age + } +}; +console.log(jonas.calcAge()); // when we call the function, the keyword age is created with its value, otherwise it doenst exist + + + +//////LOOPS LOOPS LOOPS LOOPS LOOPS LOOPS LOOPS LOOPS LOOPS LOOPS ////// + +//FOR LOOP + +//loop that goes from 1 to 10 +for (let rep = 1; rep <= 10; rep++) { + console.log(rep); +} + +for(let i = 0 ; i < years.length ;i++) // tip : no need to use -1 since we use smaller operator + +//CONTINUE + +for (let rep = 1; rep <= 10; rep++) { + if (rep === 3) continue; + console.log(rep); +} + +//BREAK +for (let rep = 1; rep <= 10; rep++) { + if (rep === 3) break; + console.log(rep); +} + +//LOOPING BACKWARDS + +for (let i = myarray.length - 1; i>=0; i--){ + console.log(i) +} + +//WHILE LOOP + +let rep = 1 //should create it outside and before the loop +while (rep <= 10){ + console.log(rep); +} + + + + + + + + + + + + + + + + + + + + + + +