diff --git a/Chapter 12/Code Samples/ch12_asyncawait.js b/Chapter 13/Code Samples/ch13_asyncawait.js similarity index 100% rename from Chapter 12/Code Samples/ch12_asyncawait.js rename to Chapter 13/Code Samples/ch13_asyncawait.js diff --git a/Chapter 12/Code Samples/ch12_callbacks.js b/Chapter 13/Code Samples/ch13_callbacks.js similarity index 100% rename from Chapter 12/Code Samples/ch12_callbacks.js rename to Chapter 13/Code Samples/ch13_callbacks.js diff --git a/Chapter 12/Code Samples/ch12_chainedpromises.js b/Chapter 13/Code Samples/ch13_chainedpromises.js similarity index 100% rename from Chapter 12/Code Samples/ch12_chainedpromises.js rename to Chapter 13/Code Samples/ch13_chainedpromises.js diff --git a/Chapter 12/Code Samples/ch12_promises.js b/Chapter 13/Code Samples/ch13_promises.js similarity index 100% rename from Chapter 12/Code Samples/ch12_promises.js rename to Chapter 13/Code Samples/ch13_promises.js diff --git a/Chapter 2/Code Samples/ch2_boolean_and_comparison.js b/Chapter 2/Code Samples/ch2_boolean_and_comparison.js new file mode 100755 index 0000000..87e5fda --- /dev/null +++ b/Chapter 2/Code Samples/ch2_boolean_and_comparison.js @@ -0,0 +1,11 @@ +let bool1 = false; +let bool2 = true; +console.log(typeof bool1) + +let str1 = "JavaScript is fun!"; +let str2 = "JavaScript is fun!"; +console.log("These two strings are the same:", str1 === str2); + +let sym1 = Symbol("JavaScript is fun!"); +let sym2 = Symbol("JavaScript is fun!"); +console.log("These two Symbols are the same:", sym1 === sym2); diff --git a/Chapter 2/Code Samples/ch2_calculations_conversions.js b/Chapter 2/Code Samples/ch2_calculations_conversions.js new file mode 100755 index 0000000..71bee3b --- /dev/null +++ b/Chapter 2/Code Samples/ch2_calculations_conversions.js @@ -0,0 +1,43 @@ +// let nr1 = 2; +// let nr2 = "2"; +// console.log(nr1 * nr2); + +// let nr1 = 2; +// let nr2 = "2"; +// console.log(nr1 + nr2); + +// let nrToStr = 6; +// nrToStr = String(nrToStr); +// console.log(nrToStr, typeof nrToStr); + +// let strToNr = "12"; +// strToNr = Number(strToNr); +// console.log(strToNr, typeof strToNr); + +// let strToBool = "any string will return true"; +// strToBool = Boolean(strToBool); +// console.log(strToBool, typeof strToBool); + +// let nullToNr = null; +// nullToNr = Number(nullToNr); +// console.log("null", nullToNr, typeof nullToNr); + +// let strToNr = ""; +// strToNr = Number(strToNr); +// console.log("empty string", strToNr, typeof strToNr); + +// let strToNr2 = "hello"; +// strToNr2 = Number(strToNr2); +// console.log(strToNr2, typeof strToNr2); + +// let strToBool = ""; +// strToBool = Boolean(strToBool); +// console.log(strToBool, typeof strToBool); + +// let strToBool2 = "false"; +// strToBool2 = Boolean(strToBool2); +// console.log(strToBool2, typeof strToBool2); + +// let nr1 = 2; +// let nr2 = "2"; +// console.log(nr1 + Number(nr2)); diff --git a/Chapter 2/Code Samples/ch2_snippets.js b/Chapter 2/Code Samples/ch2_snippets.js deleted file mode 100755 index 82254e8..0000000 --- a/Chapter 2/Code Samples/ch2_snippets.js +++ /dev/null @@ -1,184 +0,0 @@ -// let firstname = "Maria"; -// firstname = "Jacky"; - -// let nr1 = 12; -// var nr2 = 8; -// const pi = 3.14159; - -// throws a TypeError -// const someConstant = 3; -// someConstant = 4; - -// let singleString = 'Hi there!'; -// let doubleString = "How are you?"; - -// let language = "JavaScript"; -// let message = `Let's learn ${language}`; -// console.log(message); - -// let intNr = 1; -// let decNr = 1.5; -// let expNr = 1.4e15; - -// let bigNr = 90071992547409920n; -// typeError -// let result = bigNr + intNr; - -// let bool1 = false; -// let bool2 = true; -// console.log(typeof bool1) - -// let str1 = "JavaScript is fun!"; -// let str2 = "JavaScript is fun!"; -// console.log("These two strings are the same:", str1 === str2); - -// let sym1 = Symbol("JavaScript is fun!"); -// let sym2 = Symbol("JavaScript is fun!"); -// console.log("These two Symbols are the same:", sym1 === sym2); - -// let unassigned; -// console.log(unassigned); - -// let terribleThingToDo = undefined; -// let lastname; -// console.log("Same undefined:", lastname === terribleThingToDo); - -// let betterOption = null; -// console.log("Same null:", lastname === betterOption); - -// let empty = null; - -// let nr1 = 2; -// let nr2 = "2"; -// console.log(nr1 * nr2); - -// let nr1 = 2; -// let nr2 = "2"; -// console.log(nr1 + nr2); - -// let nrToStr = 6; -// nrToStr = String(nrToStr); -// console.log(nrToStr, typeof nrToStr); - -// let strToNr = "12"; -// strToNr = Number(strToNr); -// console.log(strToNr, typeof strToNr); - -// let strToBool = "any string will return true"; -// strToBool = Boolean(strToBool); -// console.log(strToBool, typeof strToBool); - -// let nullToNr = null; -// nullToNr = Number(nullToNr); -// console.log("null", nullToNr, typeof nullToNr); - -// let strToNr = ""; -// strToNr = Number(strToNr); -// console.log("empty string", strToNr, typeof strToNr); - -// let strToNr2 = "hello"; -// strToNr2 = Number(strToNr2); -// console.log(strToNr2, typeof strToNr2); - -// let strToBool = ""; -// strToBool = Boolean(strToBool); -// console.log(strToBool, typeof strToBool); - -// let strToBool2 = "false"; -// strToBool2 = Boolean(strToBool2); -// console.log(strToBool2, typeof strToBool2); - -// let nr1 = 2; -// let nr2 = "2"; -// console.log(nr1 + Number(nr2)); - -// let str = "Hello, what's your name? Is it \"Mike\"?"; -// console.log(str); -// let str2 = 'Hello, what\'s your name? Is it "Mike"?'; -// console.log(str2); - -// let str3 = "New \nline." -// let str4 = "I'm containing a backslash: \\!"; -// console.log(str3); -// console.log(str4); - -// let str = "Hello"; -// let nr = 7; -// let bigNr = 12345678901234n; -// let bool = true; -// let sym = Symbol("unique"); -// let undef = undefined; -// let unknown = null; - -// console.log("str", typeof str); -// console.log("nr", typeof nr); -// console.log("bigNr", typeof bigNr); -// console.log("bool", typeof bool); -// console.log("sym", typeof sym); -// console.log("undef", typeof undef); -// console.log("unknown", typeof unknown); - -// let nr1 = 12; -// let nr2 = 14; -// let str1 = "Hello "; -// let str2 = "addition"; -// let result1 = nr1 + nr2; -// let result2 = str1 + str2; -// console.log(result1, result2); - -// let nr1 = 20; -// let nr2 = 4; -// let str1 = "Hi "; -// let nr3 = 3; -// let result1 = nr1 - nr2; -// let result2 = str1 - nr3; -// console.log(result1, result2); - -// let nr1 = 15; -// let nr2 = 10; -// let str1 = "Hi"; -// let nr3 = 3; -// let result1 = nr1 * nr2; -// let result2 = str1 * nr3; -// console.log(result1, result2); - -// let nr1 = 30; -// let nr2 = 5; -// let result1 = nr1 / nr2; -// console.log(result1); - -// let nr1 = 2; -// let nr2 = 3; -// let result1 = nr1 ** nr2; -// console.log(result1); - -// let nr1 = 10; -// let nr2 = 3; -// let result1 = nr1 % nr2; -// console.log(`${nr1} % ${nr2} = ${result1}`); - -// let nr3 = 8; -// let nr4 = 2; -// let result2 = nr3 % nr4; -// console.log(`${nr3} % ${nr4} = ${result2}`); - -// let nr5 = 15; -// let nr6 = 4; -// let result3 = nr5 % nr6; -// console.log(`${nr5} % ${nr6} = ${result3}`); - -// let nr = 4; -// nr++; -// console.log(nr); - -// let nr = 2; -// console.log(nr++); -// console.log(nr); - -// let nr = 2; -// console.log(++nr); - -let nr1 = 4; -let nr2 = 5; -let nr3 = 2; -console.log(nr1++ + ++nr2 * nr3++); \ No newline at end of file diff --git a/Chapter 2/Code Samples/ch2_strings_and_types.js b/Chapter 2/Code Samples/ch2_strings_and_types.js new file mode 100755 index 0000000..f5bbf8f --- /dev/null +++ b/Chapter 2/Code Samples/ch2_strings_and_types.js @@ -0,0 +1,25 @@ +let str = "Hello, what's your name? Is it \"Mike\"?"; +console.log(str); +let str2 = 'Hello, what\'s your name? Is it "Mike"?'; +console.log(str2); + +let str3 = "New \nline." +let str4 = "I'm containing a backslash: \\!"; +console.log(str3); +console.log(str4); + +let str = "Hello"; +let nr = 7; +let bigNr = 12345678901234n; +let bool = true; +let sym = Symbol("unique"); +let undef = undefined; +let unknown = null; + +console.log("str", typeof str); +console.log("nr", typeof nr); +console.log("bigNr", typeof bigNr); +console.log("bool", typeof bool); +console.log("sym", typeof sym); +console.log("undef", typeof undef); +console.log("unknown", typeof unknown); diff --git a/Chapter 2/Code Samples/ch2_types_and_operations.js b/Chapter 2/Code Samples/ch2_types_and_operations.js new file mode 100755 index 0000000..fb62206 --- /dev/null +++ b/Chapter 2/Code Samples/ch2_types_and_operations.js @@ -0,0 +1,64 @@ +// let nr1 = 12; +// let nr2 = 14; +// let str1 = "Hello "; +// let str2 = "addition"; +// let result1 = nr1 + nr2; +// let result2 = str1 + str2; +// console.log(result1, result2); + +// let nr1 = 20; +// let nr2 = 4; +// let str1 = "Hi "; +// let nr3 = 3; +// let result1 = nr1 - nr2; +// let result2 = str1 - nr3; +// console.log(result1, result2); + +// let nr1 = 15; +// let nr2 = 10; +// let str1 = "Hi"; +// let nr3 = 3; +// let result1 = nr1 * nr2; +// let result2 = str1 * nr3; +// console.log(result1, result2); + +// let nr1 = 30; +// let nr2 = 5; +// let result1 = nr1 / nr2; +// console.log(result1); + +// let nr1 = 2; +// let nr2 = 3; +// let result1 = nr1 ** nr2; +// console.log(result1); + +// let nr1 = 10; +// let nr2 = 3; +// let result1 = nr1 % nr2; +// console.log(`${nr1} % ${nr2} = ${result1}`); + +// let nr3 = 8; +// let nr4 = 2; +// let result2 = nr3 % nr4; +// console.log(`${nr3} % ${nr4} = ${result2}`); + +// let nr5 = 15; +// let nr6 = 4; +// let result3 = nr5 % nr6; +// console.log(`${nr5} % ${nr6} = ${result3}`); + +// let nr = 4; +// nr++; +// console.log(nr); + +// let nr = 2; +// console.log(nr++); +// console.log(nr); + +// let nr = 2; +// console.log(++nr); + +let nr1 = 4; +let nr2 = 5; +let nr3 = 2; +console.log(nr1++ + ++nr2 * nr3++); \ No newline at end of file diff --git a/Chapter 2/Code Samples/ch2_undefined_null.js b/Chapter 2/Code Samples/ch2_undefined_null.js new file mode 100755 index 0000000..63fd30a --- /dev/null +++ b/Chapter 2/Code Samples/ch2_undefined_null.js @@ -0,0 +1,11 @@ +let unassigned; +console.log(unassigned); + +let terribleThingToDo = undefined; +let lastname; +console.log("Same undefined:", lastname === terribleThingToDo); + +let betterOption = null; +console.log("Same null:", lastname === betterOption); + +let empty = null; diff --git a/Chapter 2/Code Samples/ch2_variables_basics.js b/Chapter 2/Code Samples/ch2_variables_basics.js new file mode 100755 index 0000000..0bcb836 --- /dev/null +++ b/Chapter 2/Code Samples/ch2_variables_basics.js @@ -0,0 +1,10 @@ +let firstname = "Maria"; +firstname = "Jacky"; + +let nr1 = 12; +var nr2 = 8; +const pi = 3.14159; + +// throws a TypeError +const someConstant = 3; +someConstant = 4; diff --git a/Chapter 2/Code Samples/ch2_variables_number.js b/Chapter 2/Code Samples/ch2_variables_number.js new file mode 100755 index 0000000..e43ecd0 --- /dev/null +++ b/Chapter 2/Code Samples/ch2_variables_number.js @@ -0,0 +1,7 @@ +let intNr = 1; +let decNr = 1.5; +let expNr = 1.4e15; + +let bigNr = 90071992547409920n; +// typeError +let result = bigNr + intNr; diff --git a/Chapter 2/Code Samples/ch2_variables_string.js b/Chapter 2/Code Samples/ch2_variables_string.js new file mode 100755 index 0000000..8bff38f --- /dev/null +++ b/Chapter 2/Code Samples/ch2_variables_string.js @@ -0,0 +1,6 @@ +let singleString = 'Hi there!'; +let doubleString = "How are you?"; + +let language = "JavaScript"; +let message = `Let's learn ${language}`; +console.log(message); diff --git a/Chapter 3/Code Samples/ch3_arrays.js b/Chapter 3/Code Samples/ch3_arrays.js new file mode 100755 index 0000000..716679f --- /dev/null +++ b/Chapter 3/Code Samples/ch3_arrays.js @@ -0,0 +1,100 @@ +arr1 = new Array("purple", "green", "yellow"); +arr2 = ["black", "orange", "pink"]; + +arr3 = new Array(10); +arr4 = [10]; + +console.log(arr3); +console.log(arr4); + +cars = ["Toyota", "Renault", "Volkswagen"]; +console.log(cars[0]); +console.log(cars[1]); +console.log(cars[2]); +console.log(cars[3]); +console.log(cars[-1]); + +cars[0] = "Tesla"; +console.log(cars[0]); + +cars[3] = "Kia"; +cars[-1] = "Fiat"; +console.log(cars[3]); +console.log(cars[-1]); + +colors = ["black", "orange", "pink"] +booleans = [true, false, false, true]; +emptyArray = []; + +console.log("Length of colors:", colors.length); +console.log("Length of booleans:", booleans.length); +console.log("Length of emtpy array:", emptyArray.length); + +lastElement = colors[colors.length - 1]; +console.log(lastElement); + +numbers = [12, 24, 36]; +numbers[-1] = 0; +numbers[5] = 48; +console.log(numbers.length); + +console.log("numbers", numbers); + +favoriteFruits = ["grapefruit", "orange", "lemon"]; +favoriteFruits.push("tangerine"); + +let lengthOfFavoriteFruits = favoriteFruits.push("lime"); +console.log(lengthOfFavoriteFruits); +console.log(favoriteFruits); + +let arrOfShapes = ["circle", "triangle", "rectangle", "pentagon"]; +arrOfShapes.splice(2, 0, "square", "trapezoid"); +console.log(arrOfShapes); + +let arr5 = [1, 2, 3]; +let arr6 = [4, 5, 6]; +let arr7 = arr5.concat(arr6); +console.log(arr7); + +let arr8 = arr7.concat(7, 8, 9); +console.log(arr8); + +arr8.pop(); +console.log(arr8); + +arr8.shift(); +console.log(arr8); + +arr8.splice(1, 3); +console.log(arr8); + +delete arr8[0]; +console.log(arr8); + +let findValue = arr8.find(() => e === 6); +let findValue2 = arr8.find(() => e === 8); +console.log(findValue, findValue2); + +let findIndex = arr8.indexOf(6); +let findIndex2 = arr8.indexOf(10); +let findIndex3 = arr8.indexOf(6, 2); +console.log(findIndex, findIndex2, findIndex3); + +let animals = ["dog", "horse", "cat", "platypus", "dog"] +let lastDog = animals.lastIndexOf("dog"); +console.log(lastDog); + + +let names = ["James", "Alicia", "Fatiha", "Maria", "Bert"]; +names.sort(); + +let ages = [18, 72, 33, 56, 40]; +ages.sort(); + +console.log(names); +console.log(ages); + +names.reverse(); +console.log(names); + +console.log(typeof arr1); diff --git a/Chapter 3/Code Samples/ch3_snippets.js b/Chapter 3/Code Samples/ch3_objects.js similarity index 50% rename from Chapter 3/Code Samples/ch3_snippets.js rename to Chapter 3/Code Samples/ch3_objects.js index 675884e..8b72d8d 100755 --- a/Chapter 3/Code Samples/ch3_snippets.js +++ b/Chapter 3/Code Samples/ch3_objects.js @@ -1,104 +1,3 @@ -arr1 = new Array("purple", "green", "yellow"); -arr2 = ["black", "orange", "pink"]; - -arr3 = new Array(10); -arr4 = [10]; - -console.log(arr3); -console.log(arr4); - -cars = ["Toyota", "Renault", "Volkswagen"]; -console.log(cars[0]); -console.log(cars[1]); -console.log(cars[2]); -console.log(cars[3]); -console.log(cars[-1]); - -cars[0] = "Tesla"; -console.log(cars[0]); - -cars[3] = "Kia"; -cars[-1] = "Fiat"; -console.log(cars[3]); -console.log(cars[-1]); - -colors = ["black", "orange", "pink"] -booleans = [true, false, false, true]; -emptyArray = []; - -console.log("Length of colors:", colors.length); -console.log("Length of booleans:", booleans.length); -console.log("Length of emtpy array:", emptyArray.length); - -lastElement = colors[colors.length - 1]; -console.log(lastElement); - -numbers = [12, 24, 36]; -numbers[-1] = 0; -numbers[5] = 48; -console.log(numbers.length); - -console.log("numbers", numbers); - -favoriteFruits = ["grapefruit", "orange", "lemon"]; -favoriteFruits.push("tangerine"); - -let lengthOfFavoriteFruits = favoriteFruits.push("lime"); -console.log(lengthOfFavoriteFruits); -console.log(favoriteFruits); - -let arrOfShapes = ["circle", "triangle", "rectangle", "pentagon"]; -arrOfShapes.splice(2, 0, "square", "trapezoid"); -console.log(arrOfShapes); - -let arr5 = [1, 2, 3]; -let arr6 = [4, 5, 6]; -let arr7 = arr5.concat(arr6); -console.log(arr7); - -let arr8 = arr7.concat(7, 8, 9); -console.log(arr8); - -arr8.pop(); -console.log(arr8); - -arr8.shift(); -console.log(arr8); - -arr8.splice(1, 3); -console.log(arr8); - -delete arr8[0]; -console.log(arr8); - -let findValue = arr8.find(() => e === 6); -let findValue2 = arr8.find(() => e === 8); -console.log(findValue, findValue2); - -let findIndex = arr8.indexOf(6); -let findIndex2 = arr8.indexOf(10); -let findIndex3 = arr8.indexOf(6, 2); -console.log(findIndex, findIndex2, findIndex3); - -let animals = ["dog", "horse", "cat", "platypus", "dog"] -let lastDog = animals.lastIndexOf("dog"); -console.log(lastDog); - - -let names = ["James", "Alicia", "Fatiha", "Maria", "Bert"]; -names.sort(); - -let ages = [18, 72, 33, 56, 40]; -ages.sort(); - -console.log(names); -console.log(ages); - -names.reverse(); -console.log(names); - -console.log(typeof arr1); - let dog = { dogName: "JavaScript", weight: 2.4, color: "brown", diff --git a/Chapter 4/Code Samples/ch4_if.js b/Chapter 4/Code Samples/ch4_if.js new file mode 100755 index 0000000..41ed67f --- /dev/null +++ b/Chapter 4/Code Samples/ch4_if.js @@ -0,0 +1,49 @@ +// let rain = true; + +// if(rain){ +// console.log("** Taking my umbrella when I need to go outside **"); +// } else { +// console.log("** I can leave my umbrella at home **"); +// } + +// if(expression) { +// // code associated with the if block +// // will only be executed if the expression is true +// } else { +// // code associated with the else block +// // we don't need an else block, it is optional +// // this code will only be executed if the expression is false +// } + +let age = 16; + +if(age < 18) { + console.log("We're very sorry, but you can't get in under 18"); +} else { + console.log("Welcome!"); +} + +if(age < 3){ + console.log("Access is free under three."); +} else if(age >=3 && age < 12) { + console.log("With the child discount, the access fee is 5 dollar"); +} else if(age >=12 && age < 65) { + console.log("A regular ticket costs 10 dollar."); +} else if(age >= 65) { + console.log("A ticket is 7 dollars."); +} + +if(age < 3){ + console.log("Access is free under three."); +} else if(age < 12) { + console.log("With the child discount, the access fee is 5 dollar"); +} else if(age < 65) { + console.log("A regular ticket costs 10 dollar."); +} else if(age >= 65) { + console.log("A ticket is 7 dollars."); +} + +let access = age < 18 ? "denied" : "allowed"; +console.log(access); + +age < 18 ? console.log("denied") : console.log("allowed"); diff --git a/Chapter 4/Code Samples/ch4_snippets.js b/Chapter 4/Code Samples/ch4_switch.js similarity index 64% rename from Chapter 4/Code Samples/ch4_snippets.js rename to Chapter 4/Code Samples/ch4_switch.js index 8d3f229..83168aa 100755 --- a/Chapter 4/Code Samples/ch4_snippets.js +++ b/Chapter 4/Code Samples/ch4_switch.js @@ -1,53 +1,3 @@ -// let rain = true; - -// if(rain){ -// console.log("** Taking my umbrella when I need to go outside **"); -// } else { -// console.log("** I can leave my umbrella at home **"); -// } - -// if(expression) { -// // code associated with the if block -// // will only be executed if the expression is true -// } else { -// // code associated with the else block -// // we don't need an else block, it is optional -// // this code will only be executed if the expression is false -// } - -let age = 16; - -if(age < 18) { - console.log("We're very sorry, but you can't get in under 18"); -} else { - console.log("Welcome!"); -} - -if(age < 3){ - console.log("Access is free under three."); -} else if(age >=3 && age < 12) { - console.log("With the child discount, the access fee is 5 dollar"); -} else if(age >=12 && age < 65) { - console.log("A regular ticket costs 10 dollar."); -} else if(age >= 65) { - console.log("A ticket is 7 dollars."); -} - -if(age < 3){ - console.log("Access is free under three."); -} else if(age < 12) { - console.log("With the child discount, the access fee is 5 dollar"); -} else if(age < 65) { - console.log("A regular ticket costs 10 dollar."); -} else if(age >= 65) { - console.log("A ticket is 7 dollars."); -} - -let access = age < 18 ? "denied" : "allowed"; -console.log(access); - -age < 18 ? console.log("denied") : console.log("allowed"); - let activity = "Lunch"; if(activity === "Get up") { diff --git a/Chapter 5/Code Samples/ch5_snippets.js b/Chapter 5/Code Samples/ch5_break_continue_nested.js similarity index 50% rename from Chapter 5/Code Samples/ch5_snippets.js rename to Chapter 5/Code Samples/ch5_break_continue_nested.js index a373629..8fe1132 100755 --- a/Chapter 5/Code Samples/ch5_snippets.js +++ b/Chapter 5/Code Samples/ch5_break_continue_nested.js @@ -1,127 +1,3 @@ -let i = 0; -while (i < 10) { - console.log(i); - i++; -} - -let someArray = ["Mike", "Antal", "Marc", "Emir", "Louiza", "Jacky"]; -let notFound = true; - -while (notFound && someArray.length > 0) { - if (someArray[0] === "Louiza") { - console.log("Found her!"); - notFound = false; - } else { - someArray.shift(); - } -} - -console.log(someArray); - -let nr1 = 0; -let nr2 = 1; -let temp; -fibonacciArray = []; - -while (fibonacciArray.length < 25) { - fibonacciArray.push(nr1); - temp = nr1 + nr2; - nr1 = nr2; - nr2 = temp; -} - -console.log(fibonacciArray); - -do { - // code to be executed if the condition is true -} while (true); - -let number; -do { - number = prompt("Please enter a number between 0 and 100: "); -} while (!(number >= 0 && number < 100)); - -for (let i = 0; i < 10; i++) { - console.log(i); -} - -let arr = []; -for (let i = 0; i < 100; i++) { - arr.push(i); -} - -let arr = []; -for (let i = 0; i < 100; i = i + 2) { - arr.push(i); -} - -let arrOfArrays = []; -for (let i = 0; i < 3; i++) { - arrOfArrays.push([]); - for (let j = 0; j < 7; j++) { - arrOfArrays[i].push(j); - } -} - -console.log(arrOfArrays); - -let names = ["chantal", "john", "maxime", "bobbi", "jair"]; -for (let i = 0; i < names.length; i++) { - console.log(names[i]); -} - -//let names = ["chantal", "john", "maxime", "bobbi", "jair"]; -for (let i = 0; i < names.length; i++) { - names[i] = "hello " + names[i]; -} -console.log(names); - -for (let name of names) { - console.log(name); -} - -let car = { - model: "Golf", - make: "Volkswagen", - year: 1999, - color: "black", -}; - -for (let prop in car) { - console.log(car[prop]); -} - -for (let prop in car) { - console.log(prop); -} - -let cars = [ - { - model: "Golf", - make: "Volkswagen", - year: 1999, - color: "black", - }, - { - model: "Picanto", - make: "Kia", - year: 2020, - color: "red", - }, - { - model: "Peugeot", - make: "208", - year: 2021, - color: "black", - }, - { - model: "Fiat", - make: "Punto", - year: 2020, - color: "black", - }, -]; - for (let i = 0; i < 10; i++) { console.log(i); if (i === 4) { diff --git a/Chapter 5/Code Samples/ch5_do_while.js b/Chapter 5/Code Samples/ch5_do_while.js new file mode 100755 index 0000000..eb406e0 --- /dev/null +++ b/Chapter 5/Code Samples/ch5_do_while.js @@ -0,0 +1,8 @@ +do { + // code to be executed if the condition is true +} while (true); + +let number; +do { + number = prompt("Please enter a number between 0 and 100: "); +} while (!(number >= 0 && number < 100)); diff --git a/Chapter 5/Code Samples/ch5_for.js b/Chapter 5/Code Samples/ch5_for.js new file mode 100755 index 0000000..c778bb6 --- /dev/null +++ b/Chapter 5/Code Samples/ch5_for.js @@ -0,0 +1,34 @@ +for (let i = 0; i < 10; i++) { + console.log(i); +} + +let arr = []; +for (let i = 0; i < 100; i++) { + arr.push(i); +} + +let arr = []; +for (let i = 0; i < 100; i = i + 2) { + arr.push(i); +} + +let arrOfArrays = []; +for (let i = 0; i < 3; i++) { + arrOfArrays.push([]); + for (let j = 0; j < 7; j++) { + arrOfArrays[i].push(j); + } +} + +console.log(arrOfArrays); + +let names = ["chantal", "john", "maxime", "bobbi", "jair"]; +for (let i = 0; i < names.length; i++) { + console.log(names[i]); +} + +//let names = ["chantal", "john", "maxime", "bobbi", "jair"]; +for (let i = 0; i < names.length; i++) { + names[i] = "hello " + names[i]; +} +console.log(names); diff --git a/Chapter 5/Code Samples/ch5_for_in_for_of.js b/Chapter 5/Code Samples/ch5_for_in_for_of.js new file mode 100755 index 0000000..9d5ea1e --- /dev/null +++ b/Chapter 5/Code Samples/ch5_for_in_for_of.js @@ -0,0 +1,45 @@ +for (let name of names) { + console.log(name); +} + +let car = { + model: "Golf", + make: "Volkswagen", + year: 1999, + color: "black", +}; + +for (let prop in car) { + console.log(car[prop]); +} + +for (let prop in car) { + console.log(prop); +} + +let cars = [ + { + model: "Golf", + make: "Volkswagen", + year: 1999, + color: "black", + }, + { + model: "Picanto", + make: "Kia", + year: 2020, + color: "red", + }, + { + model: "Peugeot", + make: "208", + year: 2021, + color: "black", + }, + { + model: "Fiat", + make: "Punto", + year: 2020, + color: "black", + }, +]; diff --git a/Chapter 5/Code Samples/ch5_while.js b/Chapter 5/Code Samples/ch5_while.js new file mode 100755 index 0000000..c37ff76 --- /dev/null +++ b/Chapter 5/Code Samples/ch5_while.js @@ -0,0 +1,33 @@ +let i = 0; +while (i < 10) { + console.log(i); + i++; +} + +let someArray = ["Mike", "Antal", "Marc", "Emir", "Louiza", "Jacky"]; +let notFound = true; + +while (notFound && someArray.length > 0) { + if (someArray[0] === "Louiza") { + console.log("Found her!"); + notFound = false; + } else { + someArray.shift(); + } +} + +console.log(someArray); + +let nr1 = 0; +let nr2 = 1; +let temp; +fibonacciArray = []; + +while (fibonacciArray.length < 25) { + fibonacciArray.push(nr1); + temp = nr1 + nr2; + nr1 = nr2; + nr2 = temp; +} + +console.log(fibonacciArray); diff --git a/Chapter 6/Code Samples/ch6_anonymous_nested_callbacks.js b/Chapter 6/Code Samples/ch6_anonymous_nested_callbacks.js new file mode 100755 index 0000000..436949d --- /dev/null +++ b/Chapter 6/Code Samples/ch6_anonymous_nested_callbacks.js @@ -0,0 +1,59 @@ +function doingStuffAnonymously() { + console.log("Not so secret though."); +} + +let functionVariable = function () { + console.log("Not so secret though."); +}; + +functionVariable(); + +function doFlexibleStuff(executeStuff) { + executeStuff(); + console.log("Inside doFlexibleStuffFunction."); +} + +doFlexibleStuff(functionVariable); + +let anotherFunctionVariable = function () { + console.log("Another anonymous function implementation."); +}; + +doFlexibleStuff(anotherFunctionVariable); + +function doOuterFunctionStuff(nr) { + console.log("Outer function"); + doInnerFunctionStuff(nr); + function doInnerFunctionStuff(x) { + console.log(x + 7); + console.log("I can access outer variables:", nr); + } +} + +doOuterFunctionStuff(2); + +function doOuterFunctionStuff(nr) { + doInnerFunctionStuff(nr); + function doInnerFunctionStuff(x) { + let z = 10; + } + console.log("Not accessible:", z); +} + +doOuterFunctionStuff(2); + +function doOuterFunctionStuff(nr) { + doInnerFunctionStuff(nr); + function doInnerFunctionStuff(x) { + let z = 10; + } +} + +doInnerFunctionStuff(3); + +let youGotThis = function () { + console.log("You're doing really well, keep coding!"); +}; + +setTimeout(youGotThis, 1000); +setInterval(youGotThis, 1000); diff --git a/Chapter 6/Code Samples/ch6_functions_params.js b/Chapter 6/Code Samples/ch6_functions_params.js new file mode 100755 index 0000000..30e2a06 --- /dev/null +++ b/Chapter 6/Code Samples/ch6_functions_params.js @@ -0,0 +1,51 @@ +function hiThere() { + let you = prompt("What's your name? "); + console.log("Hello", you, "!"); +} + +hiThere(); + +console.log("this is an argument"); +prompt("argument here too"); + +let arr = []; +arr.push("argument"); + +function addTwoNumbers(x, y) { + console.log(x + y); +} + +addTwoNumbers(3, 4); +addTwoNumbers(12, -90); + +function myFunc(param1, param2) { + // code of the function; +} + +myFunc("arg1", "arg2"); + +function addTwoNumbers(x = 2, y = 3) { + console.log(x + y); +} + +addTwoNumbers(); +addTwoNumbers(6, 6); +addTwoNumbers(10); + +let favoriteSubject = prompt("What is your favorite subject?"); + +let result = addTwoNumbers(4, 5); +console.log(result); + +function addTwoNumbers(x, y) { + return x + y; +} + +let results = []; + +for (let i = 0; i < 10; i++) { + let result = addTwoNumbers(i, 2 * i); + results.push(result); +} + +console.log(results); diff --git a/Chapter 6/Code Samples/ch6_recursion.js b/Chapter 6/Code Samples/ch6_recursion.js new file mode 100755 index 0000000..969015f --- /dev/null +++ b/Chapter 6/Code Samples/ch6_recursion.js @@ -0,0 +1,35 @@ +function getRecursive(nr) { + console.log(nr); + getRecursive(--nr); +} + +getRecursive(3); + +function logRecursive(nr) { + console.log("Started function:", nr); + if (nr > 0) { + logRecursive(nr - 1); + } else { + console.log("done with recursion"); + } + console.log("Ended function:", nr); +} + +logRecursive(3); + +function getRecursive(nr) { + console.log(nr); + if (nr > 0) { + getRecursive(--nr); + } +} + +getRecursive(3); + +function calcFactorial(nr) { + if (nr === 0) { + return 1; + } else { + return nr * calcFactorial(--nr); + } +} diff --git a/Chapter 6/Code Samples/ch6_scope.js b/Chapter 6/Code Samples/ch6_scope.js new file mode 100755 index 0000000..ecc49eb --- /dev/null +++ b/Chapter 6/Code Samples/ch6_scope.js @@ -0,0 +1,72 @@ +function testAvailability(x) { + console.log("Available here:", x); +} + +testAvailability("Hi!"); +console.log("Not available here:", x); + +function testAvailability() { + let y = "Local variable!"; + console.log("Available here:", y); +} + +testAvailability(); +console.log("Not available here:", y); + +function testAvailability() { + let y = "I'll return"; + console.log("Available here:", y); + return y; +} + +let z = testAvailability(); +console.log("Outside the function:", z); +console.log("Not available here:", y); + +let globalVar = "Accessible everywhere!"; +console.log("Outside function:", globalVar); + +function creatingNewScope(x) { + console.log("Access to global variables from inside functions.", globalVar); +} + +creatingNewScope("some parameter"); + +console.log("Still available:", globalVar); + +function doingStuff() { + if (true) { + var x = "local"; + } + console.log(x); +} + +doingStuff(); + +function doingStuff() { + if (true) { + let x = "local"; + } + console.log(x); +} + +doingStuff(); + +let x = "global"; + +function doingStuff() { + let x = "local"; + console.log(x); +} + +doingStuff(); + +var x = "global"; + +function confuseReader() { + x = "Guess my scope..."; + console.log("Inside the function:", x); +} + +confuseReader(); +console.log("Outside of function:", x); diff --git a/Chapter 6/Code Samples/ch6_snippets.js b/Chapter 6/Code Samples/ch6_snippets.js deleted file mode 100755 index 1e8fa73..0000000 --- a/Chapter 6/Code Samples/ch6_snippets.js +++ /dev/null @@ -1,220 +0,0 @@ -function hiThere() { - let you = prompt("What's your name? "); - console.log("Hello", you, "!"); -} - -hiThere(); - -console.log("this is an argument"); -prompt("argument here too"); - -let arr = []; -arr.push("argument"); - -function addTwoNumbers(x, y) { - console.log(x + y); -} - -addTwoNumbers(3, 4); -addTwoNumbers(12, -90); - -function myFunc(param1, param2) { - // code of the function; -} - -myFunc("arg1", "arg2"); - -function addTwoNumbers(x = 2, y = 3) { - console.log(x + y); -} - -addTwoNumbers(); -addTwoNumbers(6, 6); -addTwoNumbers(10); - -let favoriteSubject = prompt("What is your favorite subject?"); - -let result = addTwoNumbers(4, 5); -console.log(result); - -function addTwoNumbers(x, y) { - return x + y; -} - -let results = []; - -for (let i = 0; i < 10; i++) { - let result = addTwoNumbers(i, 2 * i); - results.push(result); -} - -console.log(results); - -function testAvailability(x) { - console.log("Available here:", x); -} - -testAvailability("Hi!"); -console.log("Not available here:", x); - -function testAvailability() { - let y = "Local variable!"; - console.log("Available here:", y); -} - -testAvailability(); -console.log("Not available here:", y); - -function testAvailability() { - let y = "I'll return"; - console.log("Available here:", y); - return y; -} - -let z = testAvailability(); -console.log("Outside the function:", z); -console.log("Not available here:", y); - -let globalVar = "Accessible everywhere!"; -console.log("Outside function:", globalVar); - -function creatingNewScope(x) { - console.log("Access to global variables from inside functions.", globalVar); -} - -creatingNewScope("some parameter"); - -console.log("Still available:", globalVar); - -function doingStuff() { - if (true) { - var x = "local"; - } - console.log(x); -} - -doingStuff(); - -function doingStuff() { - if (true) { - let x = "local"; - } - console.log(x); -} - -doingStuff(); - -let x = "global"; - -function doingStuff() { - let x = "local"; - console.log(x); -} - -doingStuff(); - -var x = "global"; - -function confuseReader() { - x = "Guess my scope..."; - console.log("Inside the function:", x); -} - -confuseReader(); -console.log("Outside of function:", x); - -function getRecursive(nr) { - console.log(nr); - getRecursive(--nr); -} - -getRecursive(3); - -function logRecursive(nr) { - console.log("Started function:", nr); - if (nr > 0) { - logRecursive(nr - 1); - } else { - console.log("done with recursion"); - } - console.log("Ended function:", nr); -} - -logRecursive(3); - -function getRecursive(nr) { - console.log(nr); - if (nr > 0) { - getRecursive(--nr); - } -} - -getRecursive(3); - -function calcFactorial(nr) { - if (nr === 0) { - return 1; - } else { - return nr * calcFactorial(--nr); - } -} - -function doingStuffAnonymously() { - console.log("Not so secret though."); -} - -let functionVariable = function () { - console.log("Not so secret though."); -}; - -functionVariable(); - -function doFlexibleStuff(executeStuff) { - executeStuff(); - console.log("Inside doFlexibleStuffFunction."); -} - -doFlexibleStuff(functionVariable); - -let anotherFunctionVariable = function () { - console.log("Another anonymous function implementation."); -}; - -doFlexibleStuff(anotherFunctionVariable); - -function doOuterFunctionStuff(nr) { - console.log("Outer function"); - doInnerFunctionStuff(nr); - function doInnerFunctionStuff(x) { - console.log(x + 7); - console.log("I can access outer variables:", nr); - } -} - -doOuterFunctionStuff(2); - -function doOuterFunctionStuff(nr) { - doInnerFunctionStuff(nr); - function doInnerFunctionStuff(x) { - let z = 10; - } - console.log("Not accessible:", z); -} - -doOuterFunctionStuff(2); - -function doOuterFunctionStuff(nr) { - doInnerFunctionStuff(nr); - function doInnerFunctionStuff(x) { - let z = 10; - } -} - -doInnerFunctionStuff(3); - -let youGotThis = function () { - console.log("You're doing really well, keep coding!"); -}; - -setTimeout(youGotThis, 1000); -setInterval(youGotThis, 1000); diff --git a/Chapter 8/Code Samples/ch8_arrays.js b/Chapter 8/Code Samples/ch8_arrays.js new file mode 100644 index 0000000..d650cc5 --- /dev/null +++ b/Chapter 8/Code Samples/ch8_arrays.js @@ -0,0 +1,41 @@ +let arr = ["grapefruit", 4, "hello", 5.6, true]; +function printStuff(element, index) { + console.log("Printing stuff:", element, "on array position:", index); +} + +let arr = ["squirrel", 5, "Tjed", new Date(), true]; +function checkString(element, index) { +return typeof element === "string"; +} +let filterArr = arr.filter(checkString); +console.log(filterArr); + +console.log(arr.every(checkString)); + +arr = ["grapefruit", 4, "hello", 5.6, true]; +arr.copyWithin(0, 3, 4); + +arr = ["grapefruit", 4, "hello", 5.6, true]; +arr.copyWithin(0, 3, 5); + +let arr = ["grapefruit", 4, "hello", 5.6, true, false]; +arr.copyWithin(0, 3); +console.log(arr); + +let arr = [1, 2, 3, 4]; +let mapped_arr = arr.map(x => x + 1); +console.log(mapped_arr); + +let bb = ["so", "bye", "bye", "love"]; +console.log(bb.lastIndexOf("bye")); + +let bb = ["so", "bye", "bye", "love"]; +console.log(bb.lastIndexOf("hi")); + +let letters = ["a", "b", "c"]; +let x = letters.join(); +console.log(x); + +let letters = ["a", "b", "c"]; +let x = letters.join('-'); +console.log(x); \ No newline at end of file diff --git a/Chapter 8/Code Samples/ch8_dates.js b/Chapter 8/Code Samples/ch8_dates.js new file mode 100644 index 0000000..e8c1483 --- /dev/null +++ b/Chapter 8/Code Samples/ch8_dates.js @@ -0,0 +1,50 @@ +let currentDateTime = new Date(); +console.log(currentDateTime); + +let now2 = Date.now(); +console.log(now2); + +let milliDate = new Date(1000); +console.log(milliDate); + +let stringDate = new Date("Sat Jun 05 2021 12:40:12 GMT+0200"); +console.log(stringDate); + +let specificDate = new Date(2022, 1, 10, 12, 10, 15, 100); +console.log(specificDate); + +let d = new Date(); +console.log("Day of week:", d.getDay()); +console.log("Day of month:", d.getDate()); +console.log("Month:", d.getMonth()); +console.log("Year:", d.getFullYear()); +console.log("Seconds:", d.getSeconds()); +console.log("Milliseconds:", d.getMilliseconds()); +console.log("Time:", d.getTime()); + +d.setFullYear(2010); +console.log(d); + +d.setMonth(9); +console.log(d); + +d.setDate(10); +console.log(d); + +d.setHours(10); +console.log(d); + +d.setTime(1622889770682); +console.log(d); + +let d1 = Date.parse("June 5, 2021"); +console.log(d1); + +let d2 = Date.parse("6/5/2021"); +console.log(d2); + +console.log(d.toDateString()); + +console.log(d.toLocaleDateString()); + + diff --git a/Chapter 8/Code Samples/ch8_decode_encode.js b/Chapter 8/Code Samples/ch8_decode_encode.js new file mode 100644 index 0000000..cb9ec14 --- /dev/null +++ b/Chapter 8/Code Samples/ch8_decode_encode.js @@ -0,0 +1,12 @@ +let uri = "https://www.example.com/submit?name=maaike van putten"; +let encoded_uri = encodeURI(uri); +console.log("Encoded:", encoded_uri); +let decoded_uri = decodeURI(encoded_uri); +console.log("Decoded:", decoded_uri); + +let uri = "https://www.example.com/submit?name=maaike van putten"; +let encoded_uri = encodeURIComponent(uri); +console.log("Encoded:", encoded_uri); +let decoded_uri = decodeURIComponent(encoded_uri); +console.log("Decoded:", decoded_uri); + diff --git a/Chapter 8/Code Samples/ch8_eval.html b/Chapter 8/Code Samples/ch8_eval.html new file mode 100644 index 0000000..972a1a7 --- /dev/null +++ b/Chapter 8/Code Samples/ch8_eval.html @@ -0,0 +1,12 @@ + + +
+ + + + + \ No newline at end of file diff --git a/Chapter 8/Code Samples/ch8_examples.js b/Chapter 8/Code Samples/ch8_examples.js new file mode 100644 index 0000000..73f56a8 --- /dev/null +++ b/Chapter 8/Code Samples/ch8_examples.js @@ -0,0 +1,7 @@ +let s = "Hello"; +console.log( + s.concat(" there!") + .toUpperCase() + .replace("THERE", "you") + .concat(" You're amazing!") +); \ No newline at end of file diff --git a/Chapter 8/Code Samples/ch8_global_nan.js b/Chapter 8/Code Samples/ch8_global_nan.js new file mode 100644 index 0000000..219cac8 --- /dev/null +++ b/Chapter 8/Code Samples/ch8_global_nan.js @@ -0,0 +1,3 @@ +let x = 7; +console.log(Number.isNaN(x)); +console.log(isNaN(x)); diff --git a/Chapter 8/Code Samples/ch8_math.js b/Chapter 8/Code Samples/ch8_math.js new file mode 100644 index 0000000..47f4ea4 --- /dev/null +++ b/Chapter 8/Code Samples/ch8_math.js @@ -0,0 +1,43 @@ +let highest = Math.max(2, 56, 12, 1, 233, 4); +console.log(highest); + +let lowest = Math.min(2, 56, 12, 1, 233, 4); +console.log(lowest); + +let highestOfWords = Math.max("hi", 3, "bye"); +console.log(highestOfWords); + +let result = Math.sqrt(64); +console.log(result); + +let result2 = Math.pow(5, 3); +console.log(result2); + +let x = 6.78; +let y = 5.34; +console.log("X:", x, "becomes", Math.round(x)); +console.log("Y:", y, "becomes", Math.round(y)); + +console.log("X:", x, "becomes", Math.ceil(x)); +console.log("Y:", y, "becomes", Math.ceil(y)); + +let negativeX = -x; +let negativeY = -y; +console.log("negativeX:", negativeX, "becomes", Math.ceil(negativeX)); +console.log("negativeY:", negativeY, "becomes", Math.ceil(negativeY)); + +console.log("X:", x, "becomes", Math.floor(x)); +console.log("Y:", y, "becomes", Math.floor(y)); + +console.log("negativeX:", negativeX, "becomes", Math.floor(negativeX)); +console.log("negativeY:", negativeY, "becomes", Math.floor(negativeY)); + +console.log("X:", x, "becomes", Math.trunc(x)); +console.log("Y:", y, "becomes", Math.trunc(y)); + +let x = 2; +let exp = Math.exp(x); +console.log("Exp:", exp); +let log = Math.log(exp); +console.log("Log:", log); + diff --git a/Chapter 8/Code Samples/ch8_numbers.js b/Chapter 8/Code Samples/ch8_numbers.js new file mode 100644 index 0000000..463dbd4 --- /dev/null +++ b/Chapter 8/Code Samples/ch8_numbers.js @@ -0,0 +1,36 @@ +let x = 34; +console.log(isNaN(x)); +console.log(!isNaN(x)); +let str = "hi"; +console.log(isNaN(str)); + +let str1 = "5"; +console.log(isNaN(str1)); + +let x = 3; +let str = "finite"; +console.log(isFinite(x)); +console.log(isFinite(str)); +console.log(isFinite(Infinity)); +console.log(isFinite(10 / 0)); + +let x = 3; +let str = "integer"; +console.log(Number.isInteger(x)); +console.log(Number.isInteger(str)); +console.log(Number.isInteger(Infinity)); +console.log(Number.isInteger(2.4)); + +let x = 1.23456; +let newX = x.toFixed(2); + +let x = 1.23456; +let newX = x.toFixed(3); +console.log(x, newX); + +let x = 1.23456; +let newX = x.toPrecision(2); + +let x = 1.23456; +let newX = x.toPrecision(4); +console.log(newX) \ No newline at end of file diff --git a/Chapter 8/Code Samples/ch8_parsing.js b/Chapter 8/Code Samples/ch8_parsing.js new file mode 100644 index 0000000..5eddc50 --- /dev/null +++ b/Chapter 8/Code Samples/ch8_parsing.js @@ -0,0 +1,36 @@ +let str_int = "6"; +let int_int = parseInt(str_int); +console.log("Type of ", int_int, "is", typeof int_int); + + +let str_float = "7.6"; +let int_float = parseInt(str_float); +console.log("Type of", int_float, "is", typeof int_float); + +let str_binary = "0b101"; +let int_binary = parseInt(str_binary); +console.log("Type of", int_binary, "is", typeof int_binary); + +let str_nan = "hello!"; +let int_nan = parseInt(str_nan); +console.log("Type of", int_nan, "is", typeof int_nan); + +let str_float = "7.6"; +let float_float = parseFloat(str_float); +console.log("Type of", float_float, "is", typeof float_float); + +let str_version_nr = "2.3.4"; +let float_version_nr = parseFloat(str_version_nr); +console.log("Type of", float_version_nr, "is", typeof float_version_nr); + +let str_int = "6"; +let float_int = parseFloat(str_int); +console.log("Type of", float_int, "is", typeof float_int); + +let str_binary = "0b101"; +let float_binary = parseFloat(str_binary); +console.log("Type of", float_binary, "is", typeof float_binary); + +let str_nan = "hello!"; +let float_nan = parseFloat(str_nan); +console.log("Type of", float_nan, "is", typeof float_nan); \ No newline at end of file diff --git a/Chapter 8/Code Samples/ch8_strings.js b/Chapter 8/Code Samples/ch8_strings.js new file mode 100644 index 0000000..14b9099 --- /dev/null +++ b/Chapter 8/Code Samples/ch8_strings.js @@ -0,0 +1,95 @@ +let s1 = "Hello "; +let s2 = "JavaScript"; +let result = s1.concat(s2); +console.log(result); + +let result = "Hello JavaScript"; +let arr_result = result.split(" "); +console.log(arr_result); + +let favoriteFruits = "strawberry,watermelon,grapefruit"; +let arr_fruits = favoriteFruits.split(","); +console.log(arr_fruits); + +let letters = ["a", "b", "c"]; +let x = letters.join(); +console.log(x); + +let letters = ["a", "b", "c"]; +let x = letters.join('-'); +console.log(x); + +let poem = "Roses are red, violets are blue, if I can do JS, then you can too!"; +let index_re = poem.indexOf("re"); +console.log(index_re); + +let indexNotFound = poem.indexOf("python"); +console.log(indexNotFound); + +if (poem.indexOf("python") != -1) { + // do stuff +} + +let searchStr = "When I see my fellow, I say hello"; +let pos = searchStr.search("lo"); +console.log(pos); + +let notFound = searchStr.search("JavaScript"); +console.log(notFound); + +let lastIndex_re = poem.lastIndexOf("re"); +console.log(lastIndex_re); + +let pos1 = poem.charAt(10); +console.log(pos1); + +let pos2 = poem.charAt(1000); +console.log(pos2); + +let str = "Create a substring"; +let substr1 = str.slice(5); +let substr2 = str.slice(0,3); +console.log("1:", substr1); +console.log("2:", substr2); + +let hi = "Hi buddy"; +let new_hi = hi.replace("buddy", "Pascal"); +console.log(new_hi); + +let new_hi2 = hi.replace("not there", "never there"); +console.log(new_hi2); + +let s3 = "hello hello"; +let new_s3 = s3.replace("hello", "oh"); +console.log(new_s3); + +let s3 = "hello hello"; +let new_s3 = s3.replaceAll("hello", "oh"); +console.log(new_s3); + +let low_bye = "bye!"; +let up_bye = low_bye.toUpperCase(); +console.log(up_bye); + +let caps = "HI HOW ARE YOU?"; +let fixed_caps = caps.toLowerCase(); +console.log(fixed_caps); + +let caps = "HI HOW ARE YOU?"; +let fixed_caps = caps.toLowerCase(); +let first_capital = fixed_caps.charAt(0).toUpperCase().concat(fixed_caps.slice(1)); +console.log(first_capital); + +let encouragement = "You are doing great, keep up the good work!"; +let bool_start = encouragement.startsWith("You"); +console.log(bool_start); + +let bool_start2 = encouragement.startsWith("you"); +console.log(bool_start2); + +let bool_start3 = encouragement.toLowerCase().startsWith("you"); +console.log(bool_start3); + +let bool_end = encouragement.endsWith("Something else"); +console.log(bool_end); +