diff --git a/js/tests/3-directions.json b/js/tests/3-directions.json new file mode 100644 index 000000000..72d74a9fb --- /dev/null +++ b/js/tests/3-directions.json @@ -0,0 +1,26 @@ +[ + { + "description": "first is the value of the first element", + "code": "let list = [\n 'Harry Styles',\n 'Niall Horan',\n 'Liam Payne',\n 'Louis Tomlinson',\n // 'Zayn Malik', ??\n]\n\n// Your code\n\nequal(first, 'Harry Styles')" + }, + { + "description": "first is the value of the first element even if we change the list", + "code": "let list = [\n '2011 - Up All Night',\n '2012 - Take Me Home',\n '2013 - Midnight Memories',\n '2014 - Four',\n '2015 - Made in the A.M.',\n]\n\n// Your code\n\nequal(first, '2011 - Up All Night')" + }, + { + "description": "last is the value of the last element", + "code": "let list = [\n 'Harry Styles',\n 'Niall Horan',\n 'Liam Payne',\n 'Louis Tomlinson',\n // 'Zayn Malik', ??\n]\n\n// Your code\n\nequal(last, 'Louis Tomlinson')" + }, + { + "description": "last is the value of the last element even if we change the list", + "code": "let list = [\n '2011 - Up All Night',\n '2012 - Take Me Home',\n '2013 - Midnight Memories',\n '2014 - Four',\n '2015 - Made in the A.M.',\n]\n\n// Your code\n\nequal(last, '2015 - Made in the A.M.')" + }, + { + "description": "kiss is an array of last and first", + "code": "let list = [\n 'Harry Styles',\n 'Niall Horan',\n 'Liam Payne',\n 'Louis Tomlinson',\n // 'Zayn Malik', ??\n]\n\n// Your code\n\nequal(kiss, ['Louis Tomlinson', 'Harry Styles'])" + }, + { + "description": "kiss is an array of last and first even if we change the list", + "code": "let list = [\n '2011 - Up All Night',\n '2012 - Take Me Home',\n '2013 - Midnight Memories',\n '2014 - Four',\n '2015 - Made in the A.M.',\n]\n\n// Your code\n\nequal(kiss, ['2015 - Made in the A.M.', '2011 - Up All Night'])" + } +] \ No newline at end of file diff --git a/js/tests/a-string-of-number.json b/js/tests/a-string-of-number.json new file mode 100644 index 000000000..b1de95efd --- /dev/null +++ b/js/tests/a-string-of-number.json @@ -0,0 +1,14 @@ +[ + { + "description": "As a number, seven value is 7", + "code": "equal(Number(seven), 7)" + }, + { + "description": "As a number, seventySeven value is 77", + "code": "equal(Number(seventySeven), 77)" + }, + { + "description": "Somehow, the type of seven and seventySeven value must be strings", + "code": "equal(typeof seven, 'string')\nequal(typeof seventySeven, 'string')" + } +] \ No newline at end of file diff --git a/js/tests/access.json b/js/tests/access.json new file mode 100644 index 000000000..25565e970 --- /dev/null +++ b/js/tests/access.json @@ -0,0 +1,10 @@ +[ + { + "description": "all 3 variable should be defined and have the right values", + "code": "let human = {\n name: 'Freddy',\n age: 27,\n secureLuggage: false,\n}\n\n// Your code\n\nequal({ name, age, secureLuggage }, human)" + }, + { + "description": "value should also work for Jean-Pierre", + "code": "let human = {\n name: 'Jean-Pierre',\n age: 65,\n secureLuggage: true,\n}\n\n// Your code\n\nequal({ name, age, secureLuggage }, human)" + } +] \ No newline at end of file diff --git a/js/tests/alter-ego.json b/js/tests/alter-ego.json new file mode 100644 index 000000000..651c5b158 --- /dev/null +++ b/js/tests/alter-ego.json @@ -0,0 +1,10 @@ +[ + { + "description": "Altered object must match the expected result Edmon Dantes", + "code": "let alterEgo = {\n firstName: 'Edmond',\n lastName: 'Dantes',\n points: 247,\n}\n\n// Your code\n\nequal(alterEgo, {\n firstName: 'Edmond',\n lastName: 'Dantes',\n points: 257,\n self: 'altered',\n fullName: 'Edmond Dantes',\n})" + }, + { + "description": "Altered object must match the expected result Viktor Vaughn", + "code": "let alterEgo = {\n firstName: 'Viktor',\n lastName: 'Vaughn',\n points: 123,\n}\n\n// Your code\n\nequal(alterEgo, {\n firstName: 'Viktor',\n lastName: 'Vaughn',\n points: 133,\n self: 'altered',\n fullName: 'Viktor Vaughn',\n})" + } +] \ No newline at end of file diff --git a/js/tests/an-undefined-future.json b/js/tests/an-undefined-future.json new file mode 100644 index 000000000..d0697d5bc --- /dev/null +++ b/js/tests/an-undefined-future.json @@ -0,0 +1,6 @@ +[ + { + "description": "myFuture must be declared but its value undefined", + "code": "equal(myFuture, undefined)" + } +] \ No newline at end of file diff --git a/js/tests/anything-to-declare.json b/js/tests/anything-to-declare.json new file mode 100644 index 000000000..e27965a72 --- /dev/null +++ b/js/tests/anything-to-declare.json @@ -0,0 +1,18 @@ +[ + { + "description": "Create an age variable of your age as a number", + "code": "equal(typeof age, 'number')" + }, + { + "description": "Create a name variable of your name as a string", + "code": "equal(typeof name, 'string')" + }, + { + "description": "Create a secureLuggage variable of a boolean", + "code": "equal(typeof secureLuggage, 'boolean')" + }, + { + "description": "Values must be reasonable", + "code": "if (age <= 3) {\n throw Error(`You must be over 3 years old to pass this exericse`)\n}\n\nif (age > 99) {\n throw Error(`You are too old for this`)\n}\n\nif (name.length <= 1) {\n throw Error('Your name must be more than 1 letter long')\n}\n\nif (name.length > 99) {\n throw Error('Your name must be less than 99 letters long')\n}\n\nif (secureLuggage === false) {\n throw Error(\n `Do you really believe we are going to let you pass with insecure luggage ?!`,\n )\n}" + } +] \ No newline at end of file diff --git a/js/tests/capitalized.json b/js/tests/capitalized.json new file mode 100644 index 000000000..1eb73df1f --- /dev/null +++ b/js/tests/capitalized.json @@ -0,0 +1,14 @@ +[ + { + "description": "Test with a word all in lowercase", + "code": "let word = 'hello'\n\n// Your code\n\nequal(capitalized, 'Hello')" + }, + { + "description": "Test with a word all in uppercase", + "code": "let word = 'PRESSURE'\n\n// Your code\n\nequal(capitalized, 'Pressure')" + }, + { + "description": "Test with a word all in mixed case", + "code": "let word = 'SuPer-CoBra'\n\n// Your code\n\nequal(capitalized, 'Super-cobra')" + } +] \ No newline at end of file diff --git a/js/tests/cultural-shift.json b/js/tests/cultural-shift.json new file mode 100644 index 000000000..8bd638e06 --- /dev/null +++ b/js/tests/cultural-shift.json @@ -0,0 +1,18 @@ +[ + { + "description": "First element must be Yayoi Kusama", + "code": "const popArtists = [\n 'Andy Warhol',\n 'Keith Haring',\n 'Richard Hamilton',\n 'Ray Johnson',\n 'Marjorie Strider',\n 'Rosalyn Drexler',\n 'Roy Lichtenstein',\n 'Hariton Pushwagner',\n 'Peter Max',\n 'Robert Indiana',\n]\n\n// Your code\n\nequal(popArtists[0], 'Yayoi Kusama')" + }, + { + "description": "Last element must be Takashi Murakami", + "code": "const popArtists = [\n 'Andy Warhol',\n 'Keith Haring',\n 'Richard Hamilton',\n 'Ray Johnson',\n 'Marjorie Strider',\n 'Rosalyn Drexler',\n 'Roy Lichtenstein',\n 'Hariton Pushwagner',\n 'Peter Max',\n 'Robert Indiana',\n]\n\n// Your code\n\nequal(popArtists[popArtists.length - 1], 'Takashi Murakami')" + }, + { + "description": "Test with 10 elements", + "code": "const popArtists = [\n 'Andy Warhol',\n 'Keith Haring',\n 'Richard Hamilton',\n 'Ray Johnson',\n 'Marjorie Strider',\n 'Rosalyn Drexler',\n 'Roy Lichtenstein',\n 'Hariton Pushwagner',\n 'Peter Max',\n 'Robert Indiana',\n]\n\n// Your code\n\nequal(popArtists, [\n 'Yayoi Kusama',\n 'Andy Warhol',\n 'Keith Haring',\n 'Richard Hamilton',\n 'Ray Johnson',\n 'Marjorie Strider',\n 'Rosalyn Drexler',\n 'Roy Lichtenstein',\n 'Hariton Pushwagner',\n 'Peter Max',\n 'Robert Indiana',\n 'Takashi Murakami',\n])" + }, + { + "description": "Test with an 1 element", + "code": "const popArtists = ['Peter Max']\n\n// Your code\n\nequal(popArtists, ['Yayoi Kusama', 'Peter Max', 'Takashi Murakami'])" + } +] \ No newline at end of file diff --git a/js/tests/cut.json b/js/tests/cut.json new file mode 100644 index 000000000..34fd8e357 --- /dev/null +++ b/js/tests/cut.json @@ -0,0 +1,26 @@ +[ + { + "description": "cutFirst from the latin alphabet", + "code": "let alphabet = 'abcdefghijklmnopqrstuvwxyz'\n\n// Your code\n\nequal(cutFirst, 'klmnopqrstuvwxyz')" + }, + { + "description": "cutFirst from the georgian alphabet", + "code": "let alphabet = 'აბგდევზთიკლმნოპჟრსტუფქღყშჩცძწჭხჯჰ'\n\n// Your code\n\nequal(cutFirst, 'ლმნოპჟრსტუფქღყშჩცძწჭხჯჰ')" + }, + { + "description": "cutLast from the latin alphabet", + "code": "let alphabet = 'abcdefghijklmnopqrstuvwxyz'\n\n// Your code\n\nequal(cutLast, 'abcdefghijklmnopqrstuvw')" + }, + { + "description": "cutLast from the greek alphabet", + "code": "let alphabet = 'αβγδεζηθικλμνξοπρστυφχψω'\n\n// Your code\n\nequal(cutLast, 'αβγδεζηθικλμνξοπρστυφ')" + }, + { + "description": "cutFirstLast from the latin alphabet", + "code": "let alphabet = 'abcdefghijklmnopqrstuvwxyz'\n\n// Your code\n\nequal(cutFirstLast, 'fghijklmnopqrst')" + }, + { + "description": "cutFirstLast from the armenian alphabet", + "code": "let alphabet = 'աբգդեզէըթժիլխծկհձղճմյնշոչպջռսվտրցւփքօֆուև'\n\n// Your code\n\nequal(cutFirstLast, 'զէըթժիլխծկհձղճմյնշոչպջռսվտրցւփ')" + } +] \ No newline at end of file diff --git a/js/tests/duplicate.json b/js/tests/duplicate.json new file mode 100644 index 000000000..70d0dbcf3 --- /dev/null +++ b/js/tests/duplicate.json @@ -0,0 +1,14 @@ +[ + { + "description": "duplicate value should repeat 'I told you so'", + "code": "let sentence = 'I told you so'\n// Your code\nequal(duplicate, 'I told you so, I told you so !')" + }, + { + "description": "duplicate value should repeat 'Not again'", + "code": "let sentence = 'Not again'\n// Your code\nequal(duplicate, 'Not again, Not again !')" + }, + { + "description": "duplicate value should repeat 'I knew it'", + "code": "let sentence = 'I knew it'\n// Your code\nequal(duplicate, 'I knew it, I knew it !')" + } +] \ No newline at end of file diff --git a/js/tests/griswold-the-blacksmith.json b/js/tests/griswold-the-blacksmith.json new file mode 100644 index 000000000..2d6232c05 --- /dev/null +++ b/js/tests/griswold-the-blacksmith.json @@ -0,0 +1,22 @@ +[ + { + "description": "if the player can't buy anyting, the array should be empty", + "code": "let playerCoins = 2\n\n// Your code\n\nif (!Array.isArray(purchasableGoods)) {\n throw Error(`purchasableGoods must be declared and an array`)\n}\n\nequal(purchasableGoods.length, 0)" + }, + { + "description": "if the player can only buy arrows", + "code": "let playerCoins = 3\n\n// Your code\n\nequal(purchasableGoods, ['arrows'])" + }, + { + "description": "if the player can buy arrows and the boots", + "code": "let playerCoins = 50\n\n// Your code\n\nequal(purchasableGoods, ['arrows', 'boots'])" + }, + { + "description": "if the player can buy everything", + "code": "let playerCoins = 299.99\n\n// Your code\n\nequal(purchasableGoods, ['arrows', 'boots', 'sword'])" + }, + { + "description": "if the player can buy everything, and more", + "code": "let playerCoins = 999\n\n// Your code\n\nequal(purchasableGoods, ['arrows', 'boots', 'sword'])" + } +] \ No newline at end of file diff --git a/js/tests/half-a-million.json b/js/tests/half-a-million.json new file mode 100644 index 000000000..43b58c4c0 --- /dev/null +++ b/js/tests/half-a-million.json @@ -0,0 +1,14 @@ +[ + { + "description": "You must retrieve '1/2 MM $' from the vault using the secret", + "code": "let secret = '53CR37-k0D3'\nlet vault = { '53CR37-k0D3': '1/2 MM $' }\n// Your code\nequal(loot, '1/2 MM $')" + }, + { + "description": "You must retrieve 500000 from the vault using the secret", + "code": "let secret = '53(.-3T / typeof v)\nif (!typeOfLoggedValues.includes('number')) {\n // this is where we create the error message you see:\n throw Error('you must log a number')\n // that's what you should focus on trying to understand\n // the message, not `throw` or `Error` don't worry about\n // that, worry about showing a number in the console !\n}" + }, + { + "description": "Log a boolean in the console", + "code": "const args = saveArguments(console, 'log')\n\n// Your code\n\nconst typeOfLoggedValues = args.flat().map((v) => typeof v)\nif (!typeOfLoggedValues.includes('boolean')) {\n throw Error('you must log a boolean')\n}" + }, + { + "description": "Log a string in the console", + "code": "const args = saveArguments(console, 'log')\n\n// Your code\n\nconst typeOfLoggedValues = args.flat().map((v) => typeof v)\nif (!typeOfLoggedValues.includes('string')) {\n throw Error('you must log a string')\n}" + }, + { + "description": "Log the string Hello There ! in the console", + "code": "const args = saveArguments(console, 'log')\n\n// Your code\n\nconst loggedValues = args.flat().join(' ')\nif (!loggedValues.includes('Hello There !')) {\n throw Error('you must log the text Hello There !')\n}" + } +] \ No newline at end of file diff --git a/js/tests/inequality.json b/js/tests/inequality.json new file mode 100644 index 000000000..5f2e17924 --- /dev/null +++ b/js/tests/inequality.json @@ -0,0 +1,6 @@ +[ + { + "description": "inequality must not be equal to itself", + "code": "if (inequality === inequality) {\n throw Error(`inequality must not be equal to itself`)\n}" + } +] \ No newline at end of file diff --git a/js/tests/keep.json b/js/tests/keep.json new file mode 100644 index 000000000..6d841bf91 --- /dev/null +++ b/js/tests/keep.json @@ -0,0 +1,26 @@ +[ + { + "description": "keepFirst from the latin alphabet", + "code": "let alphabet = 'abcdefghijklmnopqrstuvwxyz'\n\n// Your code\n\nequal(keepFirst, 'abcdef')" + }, + { + "description": "keepFirst from the georgian alphabet", + "code": "let alphabet = 'აბგდევზთიკლმნოპჟრსტუფქღყშჩცძწჭხჯჰ'\n\n// Your code\n\nequal(keepFirst, 'აბგდევ')" + }, + { + "description": "keepLast from the latin alphabet", + "code": "let alphabet = 'abcdefghijklmnopqrstuvwxyz'\n\n// Your code\n\nequal(keepLast, 'tuvwxyz')" + }, + { + "description": "keepLast from the greek alphabet", + "code": "let alphabet = 'αβγδεζηθικλμνξοπρστυφχψω'\n\n// Your code\n\nequal(keepLast, 'στυφχψω')" + }, + { + "description": "keepFirstLast from the latin alphabet", + "code": "let alphabet = 'abcdefghijklmnopqrstuvwxyz'\n\n// Your code\n\nequal(keepFirstLast, 'abcwxyz')" + }, + { + "description": "keepFirstLast from the armenian alphabet", + "code": "let alphabet = 'աբգդեզէըթժիլխծկհձղճմյնշոչպջռսվտրցւփքօֆուև'\n\n// Your code\n\nequal(keepFirstLast, 'աբգֆուև')" + } +] \ No newline at end of file diff --git a/js/tests/keymaker.json b/js/tests/keymaker.json new file mode 100644 index 000000000..bd0707a8b --- /dev/null +++ b/js/tests/keymaker.json @@ -0,0 +1,18 @@ +[ + { + "description": "whiteRabbit is declared and is an object", + "code": "let secretData = { 'Mr. Reagan': 'Cypher' }\n// Your code\nif (typeof whiteRabbit !== 'object') throw Error('whiteRabbit is not declared')" + }, + { + "description": "whiteRabbit keys includes the rabbit emoji", + "code": "let secretData = { 'Mr. Reagan': 'Cypher' }\n// Your code\nif (!('🐰' in whiteRabbit)) throw Error('I could not follow the 🐰')" + }, + { + "description": "traitor value match secretData 'Mr. Reagan' property", + "code": "let secretData = { 'Mr. Reagan': 'Cypher' }\n// Your code\nequal(traitor, 'Cypher')" + }, + { + "description": "traitor value still match secretData 'Mr. Reagan' property", + "code": "let secretData = { 'Mr. Reagan': 'Cool stache' }\n// Your code\nequal(traitor, 'Cool stache')" + } +] \ No newline at end of file diff --git a/js/tests/lines.json b/js/tests/lines.json new file mode 100644 index 000000000..667b8f499 --- /dev/null +++ b/js/tests/lines.json @@ -0,0 +1,14 @@ +[ + { + "description": "Try with a lebanese poem", + "code": "let poem = `\n\nO Pyramides! C’est alors\nQue, levant ma tête pensive,\nJ'entends errer sur vos flancs forts\nL'écho de quelque voix plaintive;\nMais quoi! Serait-ce en votre sein\nQ'un orphelin pleure sa mère?\nEst-ce un hymne, est-ce une prière,\nEst-ce un gémissement divin?\n\n\n`\n\n// Your code\n\nequal(linesCount, 8)" + }, + { + "description": "Try with a french poem", + "code": "let poem = `\nComme je descendais des Fleuves impassibles,\nJe ne me sentis plus guidé par les haleurs :\nDes Peaux-Rouges criards les avaient pris pour cibles,\nLes ayant cloués nus aux poteaux de couleurs. `\n\n// Your code\n\nequal(linesCount, 4)" + }, + { + "description": "Try with an italian poem", + "code": "let poem = `Per me si va ne la città dolente,\nper me si va ne l'etterno dolore,\nper me si va tra la perduta gente.\nGiustizia mosse il mio alto fattore;\n\nfecemi la divina podestate,\nla somma sapïenza e ’l primo amore.\n\n`\n\n// Your code\n\nequal(linesCount, 7)" + } +] \ No newline at end of file diff --git a/js/tests/maximus.json b/js/tests/maximus.json new file mode 100644 index 000000000..8107aa83e --- /dev/null +++ b/js/tests/maximus.json @@ -0,0 +1,18 @@ +[ + { + "description": "oldestAge is a number", + "code": "let kevin = { age: 14 }\nlet stephanie = { age: 25 }\nlet martin = { age: 32 }\n\n// Your code\n\nequal(typeof oldestAge, 'number')" + }, + { + "description": "oldestAge is the maximum value of the age property (martin)", + "code": "let kevin = { age: 14 }\nlet stephanie = { age: 25 }\nlet martin = { age: 32 }\n\n// Your code\n\nequal(oldestAge, 32)" + }, + { + "description": "oldestAge is still the maximum value of the age property (kevin)", + "code": "let kevin = { age: 67 }\nlet stephanie = { age: 25 }\nlet martin = { age: 32 }\n\n// Your code\n\nequal(oldestAge, 67)" + }, + { + "description": "oldestAge is still the maximum value of the age property (stephanie)", + "code": "let kevin = { age: 29 }\nlet stephanie = { age: 45 }\nlet martin = { age: 32 }\n\n// Your code\n\nequal(oldestAge, 45)" + } +] \ No newline at end of file diff --git a/js/tests/mirror.json b/js/tests/mirror.json new file mode 100644 index 000000000..50a8ad4a1 --- /dev/null +++ b/js/tests/mirror.json @@ -0,0 +1,14 @@ +[ + { + "description": "mirror value is the reverse of 'devil'", + "code": "let word = 'devil'\n\n// Your code\n\nequal(mirror, 'lived')" + }, + { + "description": "mirror value is the reverse of 'dog'", + "code": "let word = 'dog'\n\n// Your code\n\nequal(mirror, 'god')" + }, + { + "description": "mirror value is the reverse of 'star'", + "code": "let word = 'star'\n\n// Your code\n\nequal(mirror, 'rats')" + } +] \ No newline at end of file diff --git a/js/tests/mixed-feelings.json b/js/tests/mixed-feelings.json new file mode 100644 index 000000000..bafe69e61 --- /dev/null +++ b/js/tests/mixed-feelings.json @@ -0,0 +1,14 @@ +[ + { + "description": "mixedFeelings must be an array", + "code": "if (!Array.isArray(mixedFeelings)) throw Error('not an array')" + }, + { + "description": "mixedFeelings must have 3 elements", + "code": "equal(mixedFeelings.length, 3)" + }, + { + "description": "every elements of mixedFeelings must be valid emotions", + "code": "const types = ['happiness', 'sadness', 'disgust', 'fear', 'surprise', 'anger']\n\nfor (const emotion of mixedFeelings) {\n if (!types.includes(emotion.type)) throw Error('emotion type is unknown')\n if (emotion.level > 9) throw Error('emotion level is to strong !')\n if (emotion.level < 0) throw Error('negative emotion level is not acceptable')\n if (typeof emotion.level !== 'number' || Number.isNaN(emotion.level)) {\n throw Error('emotion level must be a number')\n }\n}" + } +] \ No newline at end of file diff --git a/js/tests/nested-objects.json b/js/tests/nested-objects.json new file mode 100644 index 000000000..382e9552b --- /dev/null +++ b/js/tests/nested-objects.json @@ -0,0 +1,10 @@ +[ + { + "description": "address and it's street property are objects", + "code": "equal(typeof address, 'object')\nequal(typeof address.street, 'object')" + }, + { + "description": "all address properties have the correct types", + "code": "equal(typeof address.city, 'string')\nequal(typeof address.postcode, 'number')\nequal(typeof address.street.name, 'string')\nequal(typeof address.street.number, 'number')" + } +] \ No newline at end of file diff --git a/js/tests/notorious.json b/js/tests/notorious.json new file mode 100644 index 000000000..ca074c2a9 --- /dev/null +++ b/js/tests/notorious.json @@ -0,0 +1,10 @@ +[ + { + "description": "Not big enough", + "code": "if (biggie < 1.7976931348623157e308) {\n throw Error('must be bigger !')\n}" + }, + { + "description": "You can do smaller", + "code": "if (smalls > -1.7976931348623157e308) {\n throw Error('must be smaller !')\n}" + } +] \ No newline at end of file diff --git a/js/tests/object.json b/js/tests/object.json new file mode 100644 index 000000000..332f345d9 --- /dev/null +++ b/js/tests/object.json @@ -0,0 +1,18 @@ +[ + { + "description": "variable human is declared and of type object", + "code": "equal(typeof human, 'object')" + }, + { + "description": "property name from human is of type string", + "code": "equal(typeof human.name, 'string')" + }, + { + "description": "property age from human is of type number", + "code": "equal(typeof human.age, 'number')" + }, + { + "description": "property secureLuggage from human is of type boolean", + "code": "equal(typeof human.secureLuggage, 'boolean')" + } +] \ No newline at end of file diff --git a/js/tests/parenting.json b/js/tests/parenting.json new file mode 100644 index 000000000..14550cfad --- /dev/null +++ b/js/tests/parenting.json @@ -0,0 +1,14 @@ +[ + { + "description": "parent and child must be declared and", + "code": "equal(typeof parent, 'object')\nequal(typeof child, 'object')" + }, + { + "description": "parent.child must be equal to child", + "code": "equal(parent.child, child)" + }, + { + "description": "child.parent must be equal to parent", + "code": "equal(child.parent, parent)" + } +] \ No newline at end of file diff --git a/js/tests/placeholders.json b/js/tests/placeholders.json new file mode 100644 index 000000000..72864ede2 --- /dev/null +++ b/js/tests/placeholders.json @@ -0,0 +1,10 @@ +[ + { + "description": "presentation value includes age and name .", + "code": "let name = 'Patrick'\nlet age = 48\n\n// Your code\nequal(presentation, `Hello, my name is Patrick and I'm 48 years old`)" + }, + { + "description": "presentation value still includes age and name .", + "code": "let name = 'Jeremy'\nlet age = 27\n\n// Your code\nequal(presentation, `Hello, my name is Jeremy and I'm 27 years old`)" + } +] \ No newline at end of file diff --git a/js/tests/pop-art.json b/js/tests/pop-art.json new file mode 100644 index 000000000..1fc0816ee --- /dev/null +++ b/js/tests/pop-art.json @@ -0,0 +1,18 @@ +[ + { + "description": "First element must be Andy Warhol", + "code": "const popArtists = [\n 'Pablo Picasso',\n 'Andy Warhol',\n 'Keith Haring',\n 'Richard Hamilton',\n 'Ray Johnson',\n 'Marjorie Strider',\n 'Rosalyn Drexler',\n 'Roy Lichtenstein',\n 'Hariton Pushwagner',\n 'Peter Max',\n 'Robert Indiana',\n 'Louise Bourgeois',\n]\n\n// Your code\n\nequal(popArtists[0], 'Andy Warhol')" + }, + { + "description": "Last element must be Robert Indiana", + "code": "const popArtists = [\n 'Pablo Picasso',\n 'Andy Warhol',\n 'Keith Haring',\n 'Richard Hamilton',\n 'Ray Johnson',\n 'Marjorie Strider',\n 'Rosalyn Drexler',\n 'Roy Lichtenstein',\n 'Hariton Pushwagner',\n 'Peter Max',\n 'Robert Indiana',\n 'Louise Bourgeois',\n]\n\n// Your code\n\nequal(popArtists[popArtists.length - 1], 'Robert Indiana')" + }, + { + "description": "Test overall expected result with 8 elements", + "code": "const popArtists = [\n 'Pablo Picasso',\n 'Andy Warhol',\n 'Keith Haring',\n 'Richard Hamilton',\n 'Marjorie Strider',\n 'Roy Lichtenstein',\n 'Hariton Pushwagner',\n 'Peter Max',\n 'Robert Indiana',\n 'Louise Bourgeois',\n]\n\n// Your code\n\nequal(popArtists, [\n 'Andy Warhol',\n 'Keith Haring',\n 'Richard Hamilton',\n 'Marjorie Strider',\n 'Roy Lichtenstein',\n 'Hariton Pushwagner',\n 'Peter Max',\n 'Robert Indiana',\n])" + }, + { + "description": "Test overall expected result with 3 elements", + "code": "const popArtists = [\n 'Pablo Picasso',\n 'Richard Hamilton',\n 'Marjorie Strider',\n 'Peter Max',\n 'Louise Bourgeois',\n]\n\n// Your code\n\nequal(popArtists, ['Richard Hamilton', 'Marjorie Strider', 'Peter Max'])" + } +] \ No newline at end of file diff --git a/js/tests/ratchet-clap.json b/js/tests/ratchet-clap.json new file mode 100644 index 000000000..3395b84f8 --- /dev/null +++ b/js/tests/ratchet-clap.json @@ -0,0 +1,14 @@ +[ + { + "description": "Test with a classic introduction", + "code": "let words = ['Hello', 'There', '!']\n\n// Your code\n\nequal(ratchetClap, 'Hello👏There👏!👏')" + }, + { + "description": "Test with a basic catchphrase", + "code": "let words = ['Live', 'Laugh', 'Love']\n\n// Your code\n\nequal(ratchetClap, 'Live👏Laugh👏Love👏')" + }, + { + "description": "Test with a long quote", + "code": "let words = [\n 'Being',\n 'on',\n 'the',\n 'edge',\n 'isn’t',\n 'as',\n 'safe',\n 'but',\n 'the',\n 'view',\n 'is',\n 'better',\n]\n\n// Your code\n\nequal(\n ratchetClap,\n 'Being👏on👏the👏edge👏isn’t👏as👏safe👏but👏the👏view👏is👏better👏',\n)" + } +] \ No newline at end of file diff --git a/js/tests/redeclaration-of-love.json b/js/tests/redeclaration-of-love.json new file mode 100644 index 000000000..e882cdb6e --- /dev/null +++ b/js/tests/redeclaration-of-love.json @@ -0,0 +1,6 @@ +[ + { + "description": "The value of love must have changed", + "code": "let love = 'You used to love me !!'\n\n// Your code\n\nequal(love, 'I still love you !!')" + } +] \ No newline at end of file diff --git a/js/tests/smooth-operator.json b/js/tests/smooth-operator.json new file mode 100644 index 000000000..3331dd53a --- /dev/null +++ b/js/tests/smooth-operator.json @@ -0,0 +1,18 @@ +[ + { + "description": "values of the variable are a result of the operations on the variable smooth ( 10 )", + "code": "let smooth = 10\n\n// Your code\n\nequal(lessSmooth, 9)\nequal(semiSmooth, 5)\nequal(plus11, 21)" + }, + { + "description": "values of the variable are a result of the operations on the variable smooth ( 27 )", + "code": "let smooth = 27\n\n// Your code\nequal(lessSmooth, 26)\nequal(semiSmooth, 13.5)\nequal(plus11, 38)" + }, + { + "description": "ultraSmooth should be the square of the value of smooth ( 10 )", + "code": "let smooth = 10\n\n// Your code\n\nequal(ultraSmooth, 100)" + }, + { + "description": "ultraSmooth should be the square of the value of smooth ( 27 )", + "code": "let smooth = 27\n\n// Your code\n\nequal(ultraSmooth, 729)" + } +] \ No newline at end of file diff --git a/js/tests/swapy.json b/js/tests/swapy.json new file mode 100644 index 000000000..9954d8b36 --- /dev/null +++ b/js/tests/swapy.json @@ -0,0 +1,10 @@ +[ + { + "description": "replaceMe third element is 'great'", + "code": "const replaceMe = ['This', 'is', 'horrible', '!']\nconst swapMe = ['pif', 'paf', 'pom']\n\n// Your code\n\nequal(replaceMe, ['This', 'is', 'great', '!'])" + }, + { + "description": "1st and 2nd elements of swapMe are swapped pif,paf,pom", + "code": "const replaceMe = ['This', 'is', 'horrible', '!']\nconst swapMe = ['pif', 'paf', 'pom']\n\n// Your code\n\nequal(swapMe, ['paf', 'pif', 'pom'])" + } +] \ No newline at end of file diff --git a/js/tests/the-four-seasons.json b/js/tests/the-four-seasons.json new file mode 100644 index 000000000..0e25ea2a2 --- /dev/null +++ b/js/tests/the-four-seasons.json @@ -0,0 +1,26 @@ +[ + { + "description": "seasons variable must be an Array", + "code": "if (!Array.isArray(seasons)) {\n throw Error('Season must be an Array')\n}" + }, + { + "description": "seasons first element must be spring", + "code": "equal(seasons[0].toLowerCase(), 'spring')" + }, + { + "description": "seasons second element summer", + "code": "equal(seasons[1].toLowerCase(), 'summer')" + }, + { + "description": "seasons third element autumn", + "code": "equal(seasons[2].toLowerCase(), 'autumn')" + }, + { + "description": "seasons fourth element winter", + "code": "equal(seasons[3].toLowerCase(), 'winter')" + }, + { + "description": "seasons we must not have a fifth element", + "code": "equal(seasons[4], undefined)" + } +] \ No newline at end of file diff --git a/js/tests/the-great-escape.json b/js/tests/the-great-escape.json new file mode 100644 index 000000000..0bc486e05 --- /dev/null +++ b/js/tests/the-great-escape.json @@ -0,0 +1,18 @@ +[ + { + "description": "escapeFromDelimiters is declared and includes a double-quote", + "code": "if (typeof escapeFromDelimiters === 'undefined') {\n throw Error(\n `You didn't even define the variable... we've been through this already !`,\n )\n}\n\nif (!escapeFromDelimiters.includes('\"')) {\n throw Error('escapeFromDelimiters must include a double-quote\"')\n}" + }, + { + "description": "escapeFromDelimiters includes a single-quote", + "code": "if (!escapeFromDelimiters.includes(\"'\")) {\n throw Error(\"escapeFromDelimiters must include a single-quote'\")\n}" + }, + { + "description": "escapeFromDelimiters includes a backtick", + "code": "if (!escapeFromDelimiters.includes('`')) {\n throw Error('escapeFromDelimiters must include a backtick `')\n}" + }, + { + "description": "escapeTheEscape includes a backslash", + "code": "if (!new TextEncoder().encode(escapeTheEscape).includes(92)) {\n throw Error('escapeTheEscape must includes a backslash')\n}" + } +] \ No newline at end of file diff --git a/js/tests/the-true-king.json b/js/tests/the-true-king.json new file mode 100644 index 000000000..1668779ee --- /dev/null +++ b/js/tests/the-true-king.json @@ -0,0 +1,14 @@ +[ + { + "description": "if the name is 'Perceval' excalibur should stay set in stone", + "code": "let name = 'Perceval'\nlet excalibur = 'set in stone'\n\n// Your code\n\nequal(excalibur, 'set in stone')" + }, + { + "description": "if the name is 'Merlin' excalibur should stay set in stone", + "code": "let name = 'Merlin'\nlet excalibur = 'set in stone'\n\n// Your code\n\nequal(excalibur, 'set in stone')" + }, + { + "description": "if the name is 'Arthur' excalibur should be pulled", + "code": "let name = 'Arthur'\nlet excalibur = 'set in stone'\n\n// Your code\n\nequal(excalibur, 'pulled')" + } +] \ No newline at end of file diff --git a/js/tests/unchanging.json b/js/tests/unchanging.json new file mode 100644 index 000000000..1a2c77bc0 --- /dev/null +++ b/js/tests/unchanging.json @@ -0,0 +1,10 @@ +[ + { + "description": "Test to re-assign the value", + "code": "let originalValue = unchanging\ntry {\n unchanging = 'new value'\n} catch {}\n\nif (unchanging !== originalValue) {\n throw Error('unchanging value changed !')\n}" + }, + { + "description": "Test with to re-assign with another value", + "code": "let originalValue = unchanging\ntry {\n unchanging = 'another new value'\n} catch {}\n\nif (unchanging !== originalValue) {\n throw Error('unchanging value changed !')\n}" + } +] \ No newline at end of file diff --git a/js/tests/wololo.json b/js/tests/wololo.json new file mode 100644 index 000000000..464a7ff21 --- /dev/null +++ b/js/tests/wololo.json @@ -0,0 +1,18 @@ +[ + { + "description": "bool and num must be converted to string", + "code": "let bool = true\nlet num = 4 / 3\nlet str = ''\n\n// Your code\n\nequal(stringFromNumber, '1.3333333333333333')\nequal(stringFromBoolean, 'true')" + }, + { + "description": "bool and str must be converted to numbers", + "code": "let bool = true\nlet str = '43.75'\nlet num = 0\n\n// Your code\n\nequal(numberFromBoolean, 1)\nequal(numberFromString, 43.75)" + }, + { + "description": "num and str must be converted to bools", + "code": "let num = 0\nlet str = 'Hello there :)'\nlet bool = false\n\n// Your code\n\nequal(booleanFromString, true)\nequal(booleanFromNumber, false)" + }, + { + "description": "conversion should apply if we change the values", + "code": "let bool = false\nlet str = ''\nlet num = 43.75\n\n// Your code\n\nequal(stringFromNumber, '43.75')\nequal(stringFromBoolean, 'false')\nequal(numberFromBoolean, 0)\nequal(numberFromString, 0)\nequal(booleanFromString, false)\nequal(booleanFromNumber, true)" + } +] \ No newline at end of file diff --git a/js/tests/words.json b/js/tests/words.json new file mode 100644 index 000000000..72065b300 --- /dev/null +++ b/js/tests/words.json @@ -0,0 +1,14 @@ +[ + { + "description": "Test with a classic introduction", + "code": "let sentence = 'Hello There !'\n\n// Your code\n\nequal(words, ['Hello', 'There', '!'])" + }, + { + "description": "Test with a basic catchphrase", + "code": "let sentence = 'Live Laugh Love'\n\n// Your code\n\nequal(words, ['Live', 'Laugh', 'Love'])" + }, + { + "description": "Test with a long quote", + "code": "let sentence = 'Being on the edge isn’t as safe but the view is better'\n\n// Your code\n\nequal(words, [\n 'Being',\n 'on',\n 'the',\n 'edge',\n 'isn’t',\n 'as',\n 'safe',\n 'but',\n 'the',\n 'view',\n 'is',\n 'better',\n])" + } +] \ No newline at end of file diff --git a/js/tests/you-spin-me-round.json b/js/tests/you-spin-me-round.json new file mode 100644 index 000000000..02029bdd9 --- /dev/null +++ b/js/tests/you-spin-me-round.json @@ -0,0 +1,18 @@ +[ + { + "description": "rounded is defined and the result of using Math.round on num", + "code": "let num = 2.8\n\n// Your code\n\nequal(rounded, 3)" + }, + { + "description": "rounded is still the result of using Math.round on num", + "code": "let num = 2.2\n\n// Your code\n\nequal(rounded, 2)" + }, + { + "description": "truncated is defined and the result of using Math.trunc on num", + "code": "let num = 2.8\n\n// Your code\n\nequal(truncated, 2)" + }, + { + "description": "truncated is still the result of using Math.trunc on num", + "code": "let num = 3.2\n\n// Your code\n\nequal(truncated, 3)" + } +] \ No newline at end of file diff --git a/subjects/3-directions/README.md b/subjects/3-directions/README.md new file mode 100644 index 000000000..983d950e8 --- /dev/null +++ b/subjects/3-directions/README.md @@ -0,0 +1,50 @@ +## 3 Directions + +### Accessing an array value `[index]` + +Since numbers are not valid identifiers we can not use the `.` operator to +access a value in an array, but we can use the `[index]` square brackets to +access a value. + +Example: + +```js +let numberList = [10, 20, 30, 40] +console.log(numberList[0]) // -> 10 +console.log(numberList[3]) // -> 40 +console.log(numberList[6]) // -> undefined +``` + +Since we start at `0`, `[0]` will get the value at the first index. + +> note that if we try to access an element that doesn't exist we will get +> `undefined` as a value, just like non existing properties for an object. + +#### Using the `.length` property + +Another difference of the arrays is that they always keep track of how many +elements are inside them. + +You can use the `.length` property to get this value: + +```js +console.log([].length) // -> 0 +console.log([1].length) // -> 1 +console.log([1, 1, 1, 1].length) // -> 4 +``` + +### Instructions + +We provide you a variable `list` that contains some elements, you will have to +access them and assign their values to variables: + +- a variable `first` of the first element of the `list` +- a variable `last` of the last element of the `list` +- a variable `kiss` of an array of 2 elements, the last and the first element of + the `list`, in that order. + +> 🧑‍🎤 ............ Oh, ........... 🧑‍🎤 +> 🎶 .. I wanna be last, yeah ... 🎶 +> 🎵 . Baby let me be your last . 🎵 +> ✨ ... Your last first kiss ... ✨ +> ― One Direction diff --git a/subjects/a-string-of-number/README.md b/subjects/a-string-of-number/README.md new file mode 100644 index 000000000..121bbb152 --- /dev/null +++ b/subjects/a-string-of-number/README.md @@ -0,0 +1,15 @@ +## A String of Number + +Distinguishing strings and numbers. + +### Instructions + +Declare two variables: + +- use the identifier `seven` with the value being a string of the number `7` +- use the identifier `seventySeven` with the value being a string of the number + `77` + +> “Number 7 is a legendary number, many great players who have worn it. I hope I +> could do credit in the field with this number.” \ +> ― Kylian Mbappé diff --git a/subjects/access/README.md b/subjects/access/README.md new file mode 100644 index 000000000..4594545db --- /dev/null +++ b/subjects/access/README.md @@ -0,0 +1,20 @@ +## Access + +Now that we know how to define objects, let's start to use them + +### The dot opperator `.` (property accessor) + +Let's start with getting values from them. Well, turns out you already have been +doing it a lot, remember `console.log` ? + +### Instructions + +We will provide a `human` variable of type object just like the one you did in +the previous exercise + +Your job will be to decompose each property in its own variable: + +- define a `name` variable with the value of the `name` property of the `human` + variable +- same for `age` +- and same for `secureLuggage` diff --git a/subjects/all-caps/README.md b/subjects/all-caps/README.md new file mode 100644 index 000000000..8bb106c6e --- /dev/null +++ b/subjects/all-caps/README.md @@ -0,0 +1,40 @@ +## ALL CAPS + +### Methods + +Methods are a special kind of functions, they are functions called **from** +another value. + +So that's what the `.` in `console.log` is for, we call the function `log` +**from** the `console`, so it will run its actions using the console. + +Now every value types have methods in JS, for example, numbers have a special +`toFixed` method that allows you to specify how many decimals you want when you +convert them to string: + +```js +let thirdOf10 = 10 / 3 +console.log(thirdOf10) // -> 3.3333333333333335 that's a lot of precision... +console.log(thirdOf10.toFixed(3)) // -> '3.333' that's quite enough ! +console.log(thirdOf10.toFixed()) // -> with no argument, we get just '3' +``` + +So here in that second to last line we call `toFixed` from the value of the variable +`thirdOf10`, with the argument `3`, saying that we want 3 decimal numbers in our +string conversion. + +Since they are functions, they can also return values. + +### Instructions + +One of the value with the most methods are strings, you can do a lot of things +with them. + +For this exercise you will have to use the methods `toUpperCase` and `toLowerCase` from the +provided variable `message`. + +- Create a `noCaps` variable of the value of `message` but in lower case. +- Create an `allCaps` variable of the value of `message` but in upper case. + +> Just remember ALL CAPS when you spell the man name \ +> ― MF DOOM diff --git a/subjects/alter-ego/README.md b/subjects/alter-ego/README.md new file mode 100644 index 000000000..bc4125e52 --- /dev/null +++ b/subjects/alter-ego/README.md @@ -0,0 +1,55 @@ +## Alter Ego + +You can change your objects in multiple ways: + +- modify values of properties +- add new properties +- delete properties + +### Modifying objects + +Let's declare an object + +```js +// we create our object with 2 properties +const user = { + points: 0, + code: '75lai78wn', +} +``` + +#### Adding a new properperty + +```js +user.name = 'Martin' // we add a name to our user +``` + +The syntax is very similar to modifying a variable, the only difference is we +start **from** our user and use the `.` _(property accessor operator)_ + +#### Changing a property value + +```js +user.points = 10 // set points to 10 points +``` + +The syntax is the same, if the property already exist, its value will be changed +! + +#### Removing a property + +```js +user.code = undefined // remove the value from a property +``` + +The trick here is to set its value to `undefined` as this will clear the value +of our property + +### Instructions + +Modify the provided `alterEgo` variable: + +- add a `self` property with the string value `'altered'`. +- add a `fullName` property that is the joined value of the `firstName` and the + `lastName` with a space in between. +- add `10` to it's `points` property diff --git a/subjects/an-undefined-future/README.md b/subjects/an-undefined-future/README.md new file mode 100644 index 000000000..ee66578bd --- /dev/null +++ b/subjects/an-undefined-future/README.md @@ -0,0 +1,20 @@ +## An Undefined Future + +### Undefined + +In previous exercise, you might have encouter `undefined` already. + +It's the value of a variable not having a value ! + +It's saying that the value was not defined. + +### Instructions + +Find a way to declare a variable `myFuture` without defining its value + +Because after all, we don't know what your future holds ! + +> There's no future \ +> No future \ +> No future for you \ +> ― The Sex Pistols diff --git a/subjects/anything-to-declare/README.md b/subjects/anything-to-declare/README.md new file mode 100644 index 000000000..697ae2fda --- /dev/null +++ b/subjects/anything-to-declare/README.md @@ -0,0 +1,123 @@ +## Anything to Declare ? + +### Variables + +Values, need a way to be identified, that's why we use variables.\ +They add meaning to a value by _pointing_ to it. + +It's like a **label**, a way to name things. + +If we say `20`, it doesn't carry much meaning, _`20` what ?_ + +Imagine we are talking about what's in your backpack, you have 20 pairs of +socks. + +_Now that's a lot of socks !_ + +> We defined _what_ we have (pair of socks) and it's _value_ (20) + +#### Example + +An `identifier` is used to _define_ what it is, using this syntax: + +```js +let pairOfSocks = 20 +``` + +> 😱 Woa what's all this ?! + +Let's explain each parts: + +#### Keyword: `let` + +Firstly, a keyword, `let`. + +> A `keyword` is a special word that JS knows about, it is used to tell the +> computer to perform a specific action. + +`let` that indicate the script that it's defining a new variable. + +#### Identifier + +After that, it need a **valid** identifier. + +In this case it's `pairOfSocks`, we chose what ever we want here that will be +meaningful, _(it's often hard to name things correctly)_. + +A few rules to apply to make sure an identifier is valid: + +- No space allowed _(`pair of socks` would be 3 distinct identifiers)_ +- Not **starting** with a number _(that's reserved for number values)_ +- Not being a reserved keyword _(for example using `let`)_ +- No special characters + +As such we use what's called `camelCase`. + +> Note that in JS, it is a convention to not uppercase the first letter as this +> is reserved for special declarations, we won't go into details now. + +```js +let pair of socks = 20 // invalid because of spaces +let 'pair of socks' = 20 // invalid because identifiers are not strings +let pair-of-socks = 20 // invalid because of special character - +let pair.of.socks = 20 // invalid because of special character / +let 20PairOfSocks = 20 // invalid because beginning with a number +let PairOfSocks = 20 // valid but incorrect because of the uppercase +let pairOfSocks = 20 // Just right +let let = true // invalid because `let` is a JS keyword +``` + +#### Operator: `=` + +The special character `=` is an **operator**, like in math, they are used to +define specific operations. + +In this case, `=` define the `assignation` operation. + +It means assigning a value to our variable. + +This is what **links** the choosen `identifier` with our `value`. + +#### Value + +Lastly, a value, like the one you already know: `string`, `number` and +`boolean`. + +Full example with descriptive comments: + +```js +// ↙ keyword ↙ assignation operator +let comicBookTitle = 'Tintin in Tibet' +// ↖ identifier ↖ the value (here a string) +``` + +Using multiple variables to define something more complex: + +```js +// Example of variables that could represent a transaction: +let currency = 'EURO' +let amount = 77.5 +let cashPayment = false + +// Use them with console.log, like a normal value: +console.log('You have to pay:') +console.log(amount) +console.log('in') +console.log(currency) +console.log('using cash:') +console.log(cashPayment) +``` + +### Instructions + +All right, before we can embark into this adventure, you are going to tell us +more about yourself using **variables** ! + +- Declare a variable _indentified_ `age` of a `Number` value of your age + +- Declare a variable _indentified_ `name` of a `String` value of your name + +- Declare a variable _indentified_ `secureLuggage` of a `Boolean` saying if your + luggage contain dangerous things or not. _(for obvious security reasons)_ + +> PS: And please, use reasonable values, or the tests might reject you ! diff --git a/subjects/capitalized/README.md b/subjects/capitalized/README.md new file mode 100644 index 000000000..0fe7793b1 --- /dev/null +++ b/subjects/capitalized/README.md @@ -0,0 +1,11 @@ +## Capitalized + +### Instructions + +Declare a `capitalized` variable of the transformed provided variable `word` +where: + +- First character must be uppercase +- Rest of the word must be lowercase + +> No new notions here, apply some of your knew knowledge ! diff --git a/subjects/cloning-vs-copying/README.md b/subjects/cloning-vs-copying/README.md new file mode 100644 index 000000000..04d6d7df2 --- /dev/null +++ b/subjects/cloning-vs-copying/README.md @@ -0,0 +1,3 @@ +## 🌟 Cloning vs Copying + +### Instructions diff --git a/subjects/cultural-shift/README.md b/subjects/cultural-shift/README.md new file mode 100644 index 000000000..2b34453b0 --- /dev/null +++ b/subjects/cultural-shift/README.md @@ -0,0 +1,18 @@ +## Cultural Shift + +![yayoi](https://user-images.githubusercontent.com/231748/112496181-6f6fef80-8d7c-11eb-8206-3da56f696af0.jpg) + +Oh noes, Japanese artists have been left out, let's fix this ! + +### Instructions + +You must modify the provided `popArtists` array using a combination of the +`push` and `shift` array methods. + +- Add `'Yayoi Kusama'` at the begining of the array +- Add `'Takashi Murakami'` at the end of the array + +### Notions + +- [devdocs.io/javascript/global_objects/array/shift](https://devdocs.io/javascript/global_objects/array/shift) +- [devdocs.io/javascript/global_objects/array/push](https://devdocs.io/javascript/global_objects/array/push) diff --git a/subjects/cut/README.md b/subjects/cut/README.md new file mode 100644 index 000000000..9b676cc61 --- /dev/null +++ b/subjects/cut/README.md @@ -0,0 +1,16 @@ +## Cut + +### Instructions + +Using the `.slice` method and the provided `alphabet` variable which is a string of all +the character in an alphabet: + +- Declare a `cutFirst` variable that removes the 10 first characters of + `alphabet`. +- Declare a `cutLast` variable that removes the 3 last characters of `alphabet`. +- Declare a `cutFirstLast` variable that remove the 5 first characters and 6 + last characters of `alphabet`. + +### Notions + +- [devdocs.io/javascript/global_objects/string/slice](https://devdocs.io/javascript/global_objects/string/slice) diff --git a/subjects/duplicate/README.md b/subjects/duplicate/README.md new file mode 100644 index 000000000..5c3973b84 --- /dev/null +++ b/subjects/duplicate/README.md @@ -0,0 +1,13 @@ +## Duplicate + +Sometimes in life, and in learning, it's important to repeat yourself. + +Let's use string placeholders to duplicate a string, so that we can make sure we +get our point across. + +### Instructions + +Declare a variable `duplicate` that repeat the provided variable `sentence`, +separated by a `, ` and add an ` !` at the end. + +> so if sentence would be `Hello there`, we expect `Hello there, Hello there !`. diff --git a/subjects/extremes/README.md b/subjects/extremes/README.md new file mode 100644 index 000000000..9f8faacf6 --- /dev/null +++ b/subjects/extremes/README.md @@ -0,0 +1,3 @@ +## extremes + +find the bigest and smallest number of the list diff --git a/subjects/frozen-more-about-mutability/README.md b/subjects/frozen-more-about-mutability/README.md new file mode 100644 index 000000000..530764932 --- /dev/null +++ b/subjects/frozen-more-about-mutability/README.md @@ -0,0 +1,3 @@ +## 🌟 frozen: more about mutability + +### Instructions diff --git a/subjects/go-to-11/README.md b/subjects/go-to-11/README.md new file mode 100644 index 000000000..57caf0d27 --- /dev/null +++ b/subjects/go-to-11/README.md @@ -0,0 +1,3 @@ +## Go to 11 + +[These go to Eleven... — "This is Spinal Tap" (1984)](https://www.youtube.com/watch?v=hW008FcKr3Q) diff --git a/subjects/griswold-the-blacksmith/README.md b/subjects/griswold-the-blacksmith/README.md new file mode 100644 index 000000000..6c0183823 --- /dev/null +++ b/subjects/griswold-the-blacksmith/README.md @@ -0,0 +1,106 @@ +## Griswold the Blacksmith + +Methods and built-in functions are good, but must of the time we have to write +our own logic and the first block for that are **conditions**. + +### The `if` keyword + +The `if` keyword allow you to run lines of code _only if_ the condition is +right, example: + +```js +if (age > 48) { + console.log('You are over 48 years old') +} +``` + +### Condition `()` + +following our `if` is a `condition` delimited by `()` parentheses, + +### Comparaison operators `>` + +Inside our condition is a comparaison (using the _greater than_ operator `>`).\ +This code `if (age > 48)` reads: + +> If age is greater than 48, then do the following code + +There are 6 different comparaison opperators: + +- `>` _greater than_ +- `<` _lesser than_ +- `<=` _lesser than or equal_ +- `>=` _greater than or equal_ +- `===` _equal to_ +- `!==` _not equal to_ + +Every comparaison operator are _like_ functions, they take 2 arguments, one on +the right and one on the left, and return a boolean value. Either `true`, the +condition is met, or `false` if it's not. + +Since they return value, you can assign them to variables, just like functions +return values: + +```js +let age = 5 +let ageEqual5 = age === 5 // age equal to 5 +let ageNotEqual5 = age !== 5 // age not equal to 5 +console.log(ageEqual5) // true +console.log(ageNotEqual5) // false +``` + +But they are commonly used directly inside an `if` condition. + +### Scope `{}` + +After the condition, a curly brace `{` signal the begining of a scope. The scope +ends at the enclosing `}` a few lines after. + +Scopes are a way to group lines of code, this allow us to do multiple lines of +code if a condition is true. + +### Indentation `..` _(2 spaces)_ + +Upon writing code inside a scope, it's an important convention to **indent** it. + +Indenting is when spaces are added at the beging of the line, here an example of +bad code: + + +```js +if (age > 48) { +// <- without indentation ! bad bad ! unreadable !! +console.log('You are over 48 years old') +} +``` + + +good code: + +```js +if (age > 48) { + // <- with indentation, omg so clean, amazing ! + console.log('You are over 48 years old') +} +``` + +Indenting add a visual indication that the code is inside a scope, while it's +not strictly necessary for code to work, it will become very important to keep +the code clear. + +### Instructions + +You are a Griswold the Blacksmith, and you must give the list of items the +player can buy for the money he got, here is what you are selling: + +- arrows for 3 coins +- boots for 44 coins +- sword for 299.99 coins _(limited offer)_ + +Declare a `purchasableGoods` array and _conditionally_ push to it all the goods +that the player can buy. + +Use `if` condiations and compare the cost of the goods with the provided +variable `playerCoins` that contains the number of coins available + +> You must order elements by price diff --git a/subjects/half-a-million/README.md b/subjects/half-a-million/README.md new file mode 100644 index 000000000..2930bbb6d --- /dev/null +++ b/subjects/half-a-million/README.md @@ -0,0 +1,53 @@ +## Half a million + +### Using variables as keys + +One possible and very useful way to get something from an object is using a +variable value. Sometimes you don't know in advance what the key will be. + +Using variables allows your code to be flexible, let's see how to do it + +```js +let greeting = 'hello' +let say = { hello: 'my friend', hoy: 'mate' } + +// Here when we access it will use +console.log(say[greeting]) // -> 'my friend' + +// It is exactly the same as doing +console.log(say['hello']) // -> 'my friend' + +// But if we change the value of our variable: +greeting = 'hoy' + +// The same code now returns another value +console.log(say[greeting]) // -> 'mate' +``` + +We are using the `value` of the variable, not the `identifier` to access the +property, so: + +```js +console.log(say[greeting]) // -> 'mate' +console.log(say['greeting']) // -> undefined +console.log(say.greeting) // -> undefined +// greeting is the identifier, but we use it's value, here `'hoy'` +``` + +### Instructions + +In this exercise, we will do a heist. + +Our intel already worked the plan out and we are able to provide you with 2 +variables: + +- a `vault` object +- a `secret` string + +You must use the `secret` value as a key to access the matching value from the +`vault` and assign it to a variable `loot`. + +You must then replace the value from the vault by a message of your choice. + +> I sure hope you didn't do anything stupid, Jackie. \ +> ― Ray Nicolette diff --git a/subjects/hello-there/README.md b/subjects/hello-there/README.md index 79df9b48d..20d6e3cb2 100644 --- a/subjects/hello-there/README.md +++ b/subjects/hello-there/README.md @@ -1,6 +1,6 @@ -## Hello There +## Hello There 👋 -### Instructions +### Installation #### Install `Scoop` *(windows)* or `Brew` *(mac)* @@ -10,7 +10,6 @@ Follow the instructions here: > Linux people, you should know how to handle this - #### Install `git`, `vscode` and `nodejs` ```bash @@ -50,23 +49,70 @@ git config --global color.ui true > If you are adventurous, you can also setup your SSH key > this will allow you to avoid typing your password everytime. +### Values -#### Write the code ! +There are 3 types of values, and they can model the **WORLD** !\ +_(In the end it's all `1`'s and `0`'s for the computer)_, but us, **humans**, need +an easier way of representing stuff. -Once you have installed and configured the necessary tools, -create a `git` repository named `[[ROOT]]` with a `hello-there.js` -JS file that display the text `Hello There` in the terminal. +> We can all agree that `11010001100101110110011011001101111` is not a very +> friendly way to say `'hello'` ! -> Don't forget to commit and push the file to the servers +#### Numbers 🔢 + +- Whole numbers: `1`, `23`, `232139283` +- Negative numbers are prefixed with `-`: `-1`, `-1231` +- Decimal numbers: `3.14`, `-2.53343` etc... + +Use them for _quantities_ like in daily life. + +#### Booleans ✖️ / ✔️ + +- Something is `true` +- or `false` + +They represent a truth, an answer to a closed-ended question _(anything that can +be answered with yes or no)_: + +- Is paris the capital of France ? `true` +- Are you born before 1723 ? `false` +- Is your screen turned on ? `true` _(most likely)_ + +#### Strings 🆒 -### Usage +- `'Hello'` +- `'This is some text'` -```console -student@ubuntu:~/[[ROOT]]$ node hello-there.js -Hello There -student@ubuntu:~/[[ROOT]]$ +A string is a sequence of characters used to represent text, it needs +**delimiters** to define its _begining_ and _end_.\ +Delimiters are matching quotes, either `` ` ``, `"` or `'`. + +### Using `console.log` + +To display output from a script into a console, use the function `console.log`: + +```js +console.log() // <- will show an empty line ``` +Add any value between the parentheses to see it appear when the script is +executed. + +> It is very important to use this often to validate that our code is valid. The +> more it is tested, the easier it is to understand what's going on in the code +> ! +> +> In doubt, `console.log` everything, don't be shy, they are for free. + +### Instructions + +Once you have installed and configured the necessary tools, +create a `git` repository named `[[ROOT]]` with a `hello-there.js` +JS file that is a program that displays the exact text `Hello There !`, any `Number` and a +`Boolean`. + +> Don't forget to commit and push the file to the servers + ### You will learn about - Terminal diff --git a/subjects/if-methods/README.md b/subjects/if-methods/README.md new file mode 100644 index 000000000..1fc0f2bd1 --- /dev/null +++ b/subjects/if-methods/README.md @@ -0,0 +1,3 @@ +## if + `.methods()` + + startsWith / endWith diff --git a/subjects/inequality/README.md b/subjects/inequality/README.md new file mode 100644 index 000000000..1c20d3ce7 --- /dev/null +++ b/subjects/inequality/README.md @@ -0,0 +1,12 @@ +## 🌟 Inequality + +### Notions + +- [devdocs.io/javascript/global_objects/number](https://devdocs.io/javascript/global_objects/number) + +### Instructions + +Create a `inequality` value that is not equal to itself. + +> 何 !? \ +> ― Naruto, probably. diff --git a/subjects/keep/README.md b/subjects/keep/README.md new file mode 100644 index 000000000..f5778d662 --- /dev/null +++ b/subjects/keep/README.md @@ -0,0 +1,15 @@ +## Keep + +### Instructions + +Using the `.slice` method again and the provided `alphabet` variable of a string of +all the characters in an alphabet: + +- Declare a `keepFirst` variable of only the 6 first characters from `alphabet`. +- Declare a `keepLast` variable of only the 7 last characters from `alphabet`. +- Declare a `keepFirstLast` variable of the 3 first characters and 4 last + characters from `alphabet`. + +### Notions + +- [devdocs.io/javascript/global_objects/string/slice](https://devdocs.io/javascript/global_objects/string/slice) diff --git a/subjects/keymaker/README.md b/subjects/keymaker/README.md new file mode 100644 index 000000000..11a2f200e --- /dev/null +++ b/subjects/keymaker/README.md @@ -0,0 +1,71 @@ +## Keymaker + +![keymaker](https://user-images.githubusercontent.com/231748/112028342-f8461b80-8b2f-11eb-81da-f959cd146770.jpg) + +### String as keys + +So far we only used `identifiers` as keys for our `Objects`, but they are more +flexible than variables as you can use **any** strings you want ! + +#### Declaring objects with `strings` as `keys` + +When we want to use `Strings` that is not a valid `identifier` we must add +string delimiters: + +```js +let usingIdentifier = { valid: true } +let usingString = { valid: true } // they are the same +``` + +But this syntax allow us more flexibility, if we need it: + +```js +let usingSpace = { + 'Still valid !': true, + "double quotes works too": 1337, + + // but be careful: + `backtick quote DO NOT WORK !`: false, + // because of placeholders, they can not be used as easly :( + // we will see a way to make that work later on :) +} +``` + +Has we can see, here in usingSpace, I have 2 spaces and a special character, but +that still works, handy ! + +#### Accessing properties with `strings` as `keys` + +And the most usefull one is actually to access properties values using strings +as keys, for that, much like when we wanted to use a number to access a property +in our arrays, we use `[value]` _(square brackets)_: + +```js +let usingSpace = { 'Still valid !': true } + +console.log(usingSpace['Still valid !']) // true ! +``` + +#### Assigning a properties value with `strings` as `keys` + +Much like arrays too, no surprise here: + +```js +usingSpace['New key form string'] = 55 +``` + +It's the same old recipe, we access + use the `=` _(assign operator)_ to set the +value. + +### Instructions + +Now that your are a true **Keymaker** you have a few tasks to do to assert your +power. + +- declare an object `whiteRabbit` with a key that is the rabbit emoji 🐰 with + the value of your choosing +- declare a variable `traitor` that contains the value from the property + `'Mr. Reagan'` of the provided `secretData` object + +> Another way. Always another way. \ +> ― The Keymaker diff --git a/subjects/lines/README.md b/subjects/lines/README.md new file mode 100644 index 000000000..8617fdcb3 --- /dev/null +++ b/subjects/lines/README.md @@ -0,0 +1,45 @@ +## Lines + +### The new line character `'\n'` + +One other special characters in strings is the `\n` (new line), we use it to +represent a new line without having to have a new line in our string. + +Also the single and double quote delimited strings can't actually have literal +new lines: + +```js +let fewlines = '\nHello👏\nThere👏\n' +// Same string but with litteral new lines: +let usingLiteral = ` +Hello👏 +There👏 +` +``` + +You can use the literal `\n` character to split text on each lines: + +```js +let splited = ` +Hello👏 +There👏 +`.split('\n') + +console.log(splited) // ['','Hello👏','There👏', ''] +// Note that empty lines becomes empty strings ! +``` + +### Instructions + +You have been recruted to analyse a bunch of poems, your fist task is to count +the number of lines. + +- Declare a variable `linesCount` of the number of lines from the provided + `poem` variable. + +But you must ignore empty lines in the begining and the end using the `trim` +string method. + +### Notions + +- [devdocs.io/javascript/global_objects/string/trim](https://devdocs.io/javascript/global_objects/string/trim) diff --git a/subjects/maximus/README.md b/subjects/maximus/README.md new file mode 100644 index 000000000..fb0f5bc2e --- /dev/null +++ b/subjects/maximus/README.md @@ -0,0 +1,23 @@ +## Maximus + +![maximus](https://user-images.githubusercontent.com/231748/112197288-d322dd00-8c03-11eb-95e4-a5253043578d.jpg) + +### Multiple arguments + +Functions can take multiple arguments, example: + +```js +console.log('first', 2) // both arguments will appear in your console +``` + +Values are simply separated by a `,` comma, like values in an Array. + +### Instructions + +We provide you with 3 users objects assigned in their respective variables +`martin`, `kevin`, and `stephanie`. + +- Declare an `oldestAge` variable that use the `Math.max` on their `age` property + to find the oldest age. + +Hint: Maybe find out how the Math.max function works before starting this exercise. diff --git a/subjects/mirror/README.md b/subjects/mirror/README.md new file mode 100644 index 000000000..05b3adffe --- /dev/null +++ b/subjects/mirror/README.md @@ -0,0 +1,14 @@ +## Mirror + +### Instructions + +Declare a variable `mirror` of the reversed provided variable `word`. + +_example: `desserts` would be `stressed`_ + +> Note that **reverse** only exist on array, you must first find a way to +> convert the word too an array to use it ! + +### Notions + +- [devdocs.io/javascript/global_objects/array/reverse](https://devdocs.io/javascript/global_objects/array/reverse) diff --git a/subjects/mixed-feelings/README.md b/subjects/mixed-feelings/README.md new file mode 100644 index 000000000..7200f303e --- /dev/null +++ b/subjects/mixed-feelings/README.md @@ -0,0 +1,19 @@ +## Mixed Feelings + +Unlike feelings, mixed data can be great ! + +### Mixed data types + +Like objects, arrays are values and so you can have arrays of arrays, or arrays +of objects, or arrays of objects with arrays in them or... well, you get the +picture. + +### Instructions + +You must create a `mixedFeelings` variable that is an array of 3 _emotions_. + +An emotion is an object with 2 properties: + +- a `type` property of value being one of the following strings `'happiness'`, + `'sadness'`, `'disgust'`, `'fear'`, `'surprise'` or `'anger'` +- a `level` property of value being a number from `0-9` diff --git a/subjects/nested-loops-2/README.md b/subjects/nested-loops-2/README.md new file mode 100644 index 000000000..5798b0181 --- /dev/null +++ b/subjects/nested-loops-2/README.md @@ -0,0 +1,3 @@ +## nested loops 2 + +pyramid centred (padStart, padEnd) diff --git a/subjects/nested-loops-3/README.md b/subjects/nested-loops-3/README.md new file mode 100644 index 000000000..be1667478 --- /dev/null +++ b/subjects/nested-loops-3/README.md @@ -0,0 +1,3 @@ +## 🌟 nested loops 3 + +diamon (pyramid + reversed pyramid) diff --git a/subjects/nested-loops/README.md b/subjects/nested-loops/README.md new file mode 100644 index 000000000..c1497eb2a --- /dev/null +++ b/subjects/nested-loops/README.md @@ -0,0 +1,3 @@ +## nested loops ! + +pyramid 1 diff --git a/subjects/nested-objects/README.md b/subjects/nested-objects/README.md new file mode 100644 index 000000000..e4e5adf83 --- /dev/null +++ b/subjects/nested-objects/README.md @@ -0,0 +1,15 @@ +## Nested Objects + +Since objects are values, nothing stops you from having objects inside objects. + +This is very common and allows to model more complex things. + +### Instructions + +Create an object `address` with 3 properties: + +- `city` property with a value of type `String` +- `postcode` property with a value of type `Number` +- `street` property with a value of type `Object` and 2 properties: + - `name` property with a value of type `String` + - `number` property with a value of type `Number` diff --git a/subjects/notorious/README.md b/subjects/notorious/README.md new file mode 100644 index 000000000..08a434947 --- /dev/null +++ b/subjects/notorious/README.md @@ -0,0 +1,16 @@ +## 🌟 Notorious + +### Notions + +- [devdocs.io/javascript-number](https://devdocs.io/javascript-number/) + +### Instructions + +Create 2 variables + +- `biggie` with the greatest possible `number` value +- `smalls` with the smallest possible `number` value + +> “Damn right I like the life I live, because I went from negative to positive.” +> \ +> ― The Notorius B.I.G diff --git a/subjects/object/README.md b/subjects/object/README.md new file mode 100644 index 000000000..2aca794c4 --- /dev/null +++ b/subjects/object/README.md @@ -0,0 +1,81 @@ +## Object + +This exercise is about structuring multiple values together. + +### Data Structures: Objects + +In JS, `Object` are the most basic data structures, they are a way to group +values together. + +They are like a bag of values. + +#### Example + +Remember that they are different types of variables: + +```js +let currency = 'EURO' +let amount = 77.5 +let cashPayment = false +``` + +Now we can group them all in an **object**, as objects are values too, let's +assign one to a `transaction` variable: + +```js +let transaction = { + currency: 'EURO', + amount: 77.5, + cashPayment: false, +} +console.log(transaction) // will show the object transaction +``` + +The variable `transaction` is declared and its value type is an object. + +Let's explain each parts: + +#### Object litteral syntax: `{}` + +Starting with curly brackets `{}`, they are the delimiters of our object. + +```js +let empty = {} // an empty object +``` + +#### Properties + +They define what we want inside our objects. They are composed of two elements: + +- a `key` +- and a `value` + +```js +// ↙ begining of the declaration +let transaction = { + // ↙ property key + currency: 'EURO', + // ↖ property value +} +// ↖ end of the declaration +``` + +We separate them with a `:`, to simplify, we will only use valid identifiers as +keys at the moment. + +Each properties must be separated with a `,` + +> Note that it's easier to always add a trailing `,` on every properties, but it +> is not required for the last property. + +### Instructions + +Declare a variable `human` which has a value **an object** with 3 properties: + +- a `name` property of your name as a `String` +- an `age` property of your age as a `Number` +- a `secureLuggage` of a `Boolean` saying if your luggage contain dangerous + things or not. _(still, for obvious security reasons)_ + +> “I paint objects as I think them, not as I see them.” \ +> ― Pablo Picasso diff --git a/subjects/parenting/README.md b/subjects/parenting/README.md new file mode 100644 index 000000000..284fd7b7f --- /dev/null +++ b/subjects/parenting/README.md @@ -0,0 +1,25 @@ +## 🌟 Parenting + +You are now beginning **BONUS** exercises, those are made to make you explore JS +a bit more by yourself and show you more obscure / weird aspects of the +language. + +**Only spend time on those if you are ahead !** + +If you feel already a bit overwhelmed by all you had to learn so far, don't feel +bad to skip them. + +### Circular Structure + +We call a circular Structure when an object has a property which value is +itself. + +### Instructions + +You will make such circular structure by representing a `parent` / `child` +relationship. + +Declare 2 variables of objects: + +- The object `parent` with a `child` property of the `child` object +- The object `child` with a `parent` property of the `parent` object diff --git a/subjects/placeholders/README.md b/subjects/placeholders/README.md new file mode 100644 index 000000000..507fd59ce --- /dev/null +++ b/subjects/placeholders/README.md @@ -0,0 +1,34 @@ +## Placeholders + +Enough about numbers, let's check out what we can do with strings ! + +### Strings `` `${placeholders}` `` + +The first one are `placeholders` for using values inside our strings, they have +there own syntax: `${}`. + +#### Example + +```js +console.log(`5 + 10 = ${5 + 10} = 15`) // -> 5 + 10 = 15 = 15 +``` + +**Note that it only works using:** the `` ` `` backtick, not the `"` or `'` +quotes. + +```js +// here, with the use of quotes instead of backticks, the placeholder is not evaluated and we see it as text: +console.log('5 + 10 = ${5 + 10} = 15') // -> 5 + 10 = ${5 + 10} = 15 +``` + +### Instructions + +We will provide a variable `name` and `age`. They will be pre-declared by us. + +Declare a `presentation` variable of the string: + +> `Hello, my name is` **name** `and I'm` **age** `years old` + +But use placeholders to build the string you will put inside `presentation`. +Put the values of the provided variables `age` and `name` inside those +placeholders. diff --git a/subjects/pop-art/README.md b/subjects/pop-art/README.md new file mode 100644 index 000000000..288b1e916 --- /dev/null +++ b/subjects/pop-art/README.md @@ -0,0 +1,18 @@ +## Pop Art + +### Instructions + +You must modify the provided `popArtists` array using a combination of the +`pop`, `push`, `shift` and `unshift` array methods. + +> Do not to create a new one, just change it ! + +- Remove `'Pablo Picasso'` (first) and `'Louise Bourgeois'` (last) from the list + as they are not pop artist +- Add `'Andy Warhol'` at the begining of the array +- Add `'Robert Indiana'` at the end of the array + +### Notions + +- [devdocs.io/javascript/global_objects/array/pop](https://devdocs.io/javascript/global_objects/array/pop) +- [devdocs.io/javascript/global_objects/array/unshift](https://devdocs.io/javascript/global_objects/array/unshift) diff --git a/subjects/ratchet-clap/README.md b/subjects/ratchet-clap/README.md new file mode 100644 index 000000000..66decd1c3 --- /dev/null +++ b/subjects/ratchet-clap/README.md @@ -0,0 +1,16 @@ +## Ratchet Clap + +Let's do the opposite ! + +### Instructions + +Use the provided `words` variable of an array of strings and **join** it using +the 👏 emoji. + +Also add one more 👏 at the end of the sentence, for good measure ! + +Assign the result in a `ratchetClap` variable + +### Notions + +- [devdocs.io/javascript/global_objects/string/join](https://devdocs.io/javascript/global_objects/string/join) diff --git a/subjects/redeclaration-of-love/README.md b/subjects/redeclaration-of-love/README.md new file mode 100644 index 000000000..cc1a70b3d --- /dev/null +++ b/subjects/redeclaration-of-love/README.md @@ -0,0 +1,31 @@ +## Redeclaration of Love + +### Assign, re-assign + +Remember the `let` keyword used to declare new variables. + +> Note that we can't have multiple variables with the same identifier otherwise +> JS wouldn't know which one is which. + +Redeclaring a variable will crash ! + +But it is still possible to use the `=` _(assignation operator)_ to change its +value ! + +### Instructions + +The variable `love` has been declared and will be used during the tests. + +You must try to re-assign the `love` variable to the string value +`I still love you !!` but without re-declaring it ! + +> Note that sometimes you may find variable declared with `const`. This means +> that the assignation is constant and can never be re-assigned ! +> +> It is used to protect your code against errors, but you can always use `let` +> in its place. +> +> Also you may find online old code using `var`. We are trying to get rid of +> `var`'s since 2015. It's ancient syntax and it was pretty problematic. Never +> use it! If you see code using it, try to find a more recent example. This one +> is outdated. diff --git a/subjects/repeated/README.md b/subjects/repeated/README.md new file mode 100644 index 000000000..fbd884015 --- /dev/null +++ b/subjects/repeated/README.md @@ -0,0 +1,3 @@ +## repeated + +repeat a string N times, without using the method diff --git a/subjects/seeker-of-truth/README.md b/subjects/seeker-of-truth/README.md new file mode 100644 index 000000000..684a11864 --- /dev/null +++ b/subjects/seeker-of-truth/README.md @@ -0,0 +1,50 @@ +## Seeker of Truth + +### Truthy and Falsy + +In JS, all values are either **truthy** or **falsy**, this means if used in a condition, truthy values will validate the condition while falsy values would not. + +Here is the list of falsy values: +- `undefined` and `null` +- the numbers `0` and `NaN` +- the empty string `''` +- and the boolean `false` of course + +All other values are truthy, note that empty arrays and empty objects are truthy, but the empty string is not. + +```js +if ('') { + console.log('Since empty string are falsy, this will never log') +} + +if ('hello') { + console.log('this will always log as the string is not empty') +} +``` + +### Operator `!` + +The `!` (NOT operator) can be used to convert a truthy value to `false` or a falsy value to `true`. + +example: + +```js +let money = 0 +let noMoney = !money + +console.log(noMoney) // true +``` + +In this case, 0 is falsy, so the `!` return the value `true` + +### Instructions + +R + +```js +let truth = 0 + +if (!truth) { + console.log() +} +``` diff --git a/subjects/smooth-operator/README.md b/subjects/smooth-operator/README.md new file mode 100644 index 000000000..8fc6ab1ab --- /dev/null +++ b/subjects/smooth-operator/README.md @@ -0,0 +1,56 @@ +## Smooth Operator + +![sade](https://user-images.githubusercontent.com/231748/112029913-a0101900-8b31-11eb-8f59-cd7d68d7269b.jpg) + +### Math Operators + +They are other operators than assignation, for now let's focus on the one you +probably already know: + +- `+` Addition +- `-` Substraction +- `/` Division +- `*` Multiplication + +Those operators are used the same way we would write them in math: + +```js +console.log(5 + 7) // -> 12 +console.log(5 * 5) // -> 25 +console.log(7 - 5) // -> 2 +console.log(9 / 3) // -> 3 +``` + +Operators are evaluated using classic priority: + +```js +console.log(1 + 5 * 10) // -> 51 +``` + +you can use parens `()` to enforce priority: + +```js +console.log((1 + 5) * 10) // -> 60 +``` + +And they are resulting in a value, as such they can be assigned to variables: + +```js +let halfMyAge = 33 / 2 +let twiceMyAge = 33 * 2 +``` + +### Instructions + +Your code must use the given variable `smooth` as our initial value + +You will declare a few variables: + +- `lessSmooth` that is just `1` less than `smooth` +- `semiSmooth` that is the half the amount of `smooth` _(it's still pretty + smooth)_ +- `plus11` that is `smooth` plus `11` +- `ultraSmooth` that is the square of smooth _(now that's smooth !)_ + +> BGM: +> [Sade - Smooth Operator - Official - 1984](https://www.youtube.com/watch?v=4TYv2PhG89A) diff --git a/subjects/swapy/README.md b/subjects/swapy/README.md new file mode 100644 index 000000000..2f05b0490 --- /dev/null +++ b/subjects/swapy/README.md @@ -0,0 +1,53 @@ +## Swapy + +Like we did with `Objects`, we can modify our arrays. + +### replacing an `Array` value + +Let's look at an example of code: + +```js +let weekDays = [ + 'Monday', + 'Tuesday', + 'Wednesday', + 'Thursday', + 'Friday', + 'Saturday', + 'Sunday', +] + +// Let's say I don't want Monday but a Second Sunday +weekDays[0] = 'Second Sunday' +``` + +In this example, we select the element at index `0` (with `weekDays[0]`) and +then assign it using the `=` (assign operator) the value `'Second Sunday'` + +Now my array look like this: + +```js +;[ + 'Second Sunday', + 'Tuesday', + 'Wednesday', + 'Thursday', + 'Friday', + 'Saturday', + 'Sunday', +] +``` + +### Instructions + +- You must replace the third element of the provided `replaceMe` array by the + string `'great'` +- You must swap the first and second element of the provided `swapMe` array. + +Example: + +```js +['pif','paf','pom'] -> ['paf','pif','pom'] // last element is untouched +``` + +> You must modify the `swapMe` array, not create a new one ! diff --git a/subjects/the-four-seasons/README.md b/subjects/the-four-seasons/README.md new file mode 100644 index 000000000..fa027d5f8 --- /dev/null +++ b/subjects/the-four-seasons/README.md @@ -0,0 +1,47 @@ +## The Four Seasons + +Sometimes we don't need a key, we just want a list of things, JS has a special +type for that + +### Arrays + +Let's see an example of an `Array`: + +```js +let numberArray = [ + 10, // <- no keys ! + 20, + 30, + 40, +] + +// or for brievety, we often write them on a single line like so: +let numberArray = [10, 20, 30, 40] +``` + +`Arrays` are like objects but use `[]` square bracket delimiters and only +specify values. + +The `key` of an element of an array is its position, starting from `0`. We call +that its `index` + +So our `numberArray` is **roughly equivalent** to writing this object: + +```js +let numberObject = { + 0: 10, + 1: 20, + 2: 30, + 3: 40, +} +``` + +### Instructions + +You must declare a variable `seasons` that contains 4 strings, one for each +seasons. + +Starting with Spring, like the work of the Maestro Vivaldi. + +> BGM: +> [Antonio Vivaldi - Le Quattro Stagioni](https://www.youtube.com/watch?v=b4YNYf39mcg) diff --git a/subjects/the-great-escape/README.md b/subjects/the-great-escape/README.md new file mode 100644 index 000000000..db98da446 --- /dev/null +++ b/subjects/the-great-escape/README.md @@ -0,0 +1,41 @@ +## The Great Escape + +### Escaping + +**Quote delimiters** can be one of the tricky things to deal with. + +Since they are used for delimiting text, they need a trick to include them in +our text. + +For example, we want a `'` _(single quote)_ in or text, but use them as +delimiters: + +```js +console.log('Houdini once said:') +console.log('Magic is the sole science not accepted by scientists,') +// Uh oh... ↙ JS thinks your string ends here +console.log(' because they can't understand it.') +// ...and new starts here ↖ that never finish ! +// too bad ! a quote, ruined by quotes, ironic and very sad. +``` + +The `\` _(backslash)_ is used for that: + +Everytime there is an _extra special_ character into your string, putting a `\` +in front of it will **escape** it and doing so will let JS understand you meant +the **litteral** following character and not the delimiter, _or whatever else +the character normaly means for a string_ + +### Instructions + +Nothing can stop you now with that new knowledge. Like Houdini, master of +escapes, you are going to escape some strings: + +- Create a `escapeFromDelimiters` that includes all 3 quotes _(`` ` ``, `"` and + `'`)_. + +- Create a `escapeTheEscape` that includes a backslash _(`\`)_. + +> “How did I escape? With difficulty. How did I plan this moment? With +> pleasure.” \ +> ― Alexandre Dumas, The Count of Monte Cristo diff --git a/subjects/the-true-king/README.md b/subjects/the-true-king/README.md new file mode 100644 index 000000000..27859dcc3 --- /dev/null +++ b/subjects/the-true-king/README.md @@ -0,0 +1,6 @@ +## The True King + +### Instructions + +if the provided variable `name` is the string `'Arthur'` you must change the +value of the provided variable `excalibur` to `'pulled'` diff --git a/subjects/unchanging/README.md b/subjects/unchanging/README.md new file mode 100644 index 000000000..44a1de3c0 --- /dev/null +++ b/subjects/unchanging/README.md @@ -0,0 +1,15 @@ +## 🌟 Unchanging + +You are now begining **BONUS** exercises, those are made to make you explore JS +a bit more by yourself and show you more obscure / weird aspects of the +language. + +**Only spend time on those if you are ahead !** + +If you feel already a bit overwhelmed by all you had to learn so far, don't feel +bad to skip them. + +### Instructions + +Declare a variable `unchanging` of the value of your choice, but you must make +sure it can not be re-assigned. diff --git a/subjects/what-else/README.md b/subjects/what-else/README.md new file mode 100644 index 000000000..002bd2584 --- /dev/null +++ b/subjects/what-else/README.md @@ -0,0 +1,3 @@ +## What else ? + + if / else + includes? diff --git a/subjects/wololo/README.md b/subjects/wololo/README.md new file mode 100644 index 000000000..7812b4d0e --- /dev/null +++ b/subjects/wololo/README.md @@ -0,0 +1,51 @@ +## 🌟 Wololo + +### Converting types + +As you now know, the number `42` is different than the string `'42'`, but if we +write `` `${42}` `` we converted the number to a string ! + +We see it because of the delimiters, but it is also true for the memory in your +computer. + +For example we can not multiply strings, if you try to do `'hello' * 2` or +`'hello' * 'hello'` you will have an unexpected result. + +> Well what were you expecting really ? `'hellohello'` maybe ? + +So sometimes it is usefull to go from strings to number to boolean _and back !_ + +- `Number` is a function to convert to a number. +- `Boolean` is a function to convert to a boolean. +- `String` is a function to convert to, you guessed it, a string. + +So to convert a `boolean` to a `string` we would write: + +```js +String(true) +``` + +One other way we can use `placeholders` for, is to convert from any values to a +string, but using functions is more clear than abusing placeholder syntax: + +```js +let str42Placeholder = `${42}` // was this a mistake ? +let str42Function = String(42) // ah okey we want a string ! +``` + +> so there you have it, calling, arguments and return values, let's see you +> apply all of that now + +### Instructions + +For this exercise, we provide 3 variables `num`, `bool` and `str` of a matching +type. + +Using the magical power of functions, execute the following conversions: + +- a `stringFromNumber` variable of the converted value of `num` to a `string` +- a `stringFromBoolean` variable of the converted value of `bool` to a `string` +- a `numberFromString` variable of the converted value of `str` to a `number` +- a `numberFromBoolean` variable of the converted value of `bool` to a `number` +- a `booleanFromString` variable of the converted value of `str` to a `boolean` +- a `booleanFromNumber` variable of the converted value of `num` to a `boolean` diff --git a/subjects/words/README.md b/subjects/words/README.md new file mode 100644 index 000000000..ff27b417e --- /dev/null +++ b/subjects/words/README.md @@ -0,0 +1,12 @@ +## Words + +### Instructions + +**Split** the provided variable `sentence` on spaces to create an array of words +that you will assign to a `words` variable that you will declare. + +Hint: Check the link below to see what the method split does. + +### Notions + +- [devdocs.io/javascript/global_objects/string/split](https://devdocs.io/javascript/global_objects/string/split) diff --git a/subjects/you-spin-me-round/README.md b/subjects/you-spin-me-round/README.md new file mode 100644 index 000000000..b140475cd --- /dev/null +++ b/subjects/you-spin-me-round/README.md @@ -0,0 +1,104 @@ +## You Spin Me Round + +### Functions + +Functions in JS allows you to describe multiple `instructions`, in other words, +it's a way to execute code inside your code ! + +That seems pretty complicated but it is the build block of your programs. + +You already have been using a `function` as `console.log` is one ! You can easly +spot them because we stick parens after their identifiers `()`. + +For example, here's a **function call**: + +```js +// ↙ identifier, like variables +console.log('Hello There !') +// ↖ open paren + argument + close paren +``` + +#### Function name (`identifier` or `property.key`) + +The first things that appears in a function is the `identifier`, in fact, in JS, +functions are values of type `function`. +This means that in order to be used a function **must** be either assigned to: +- a variable +- or an object property + +#### Function calling + +Functions **do** something, and they can **return a result**, a value. + +`console.log` does not return a value, but it will do something: make its +arguments appear in the console. + +To `call` the function, in other word run it, we need too add `()`. + +```js +console.log // function is not used, nothing happen +console.log() // function was called ! an empty line appear in the console +console.log(4) // function was called with 4 and it appears in the console +``` + +#### Function `arguments` + +So in that last example, number `4` was the argument of the `console.log` +function. + +A function will execute the same code on different arguments, making them +flexible. + +> Sometimes, `arguments` are named `parameters`. We just like to use 10 +> different names for everything to sound _"smart"_. + +JS gives you plenty of readymade functions, for now we are going to focus on +`Math` functions. + +#### function `return values` + +All functions from the JS `Math` object do nothing other than compute a new +value from its argument. + +For example, the well named `Math.round` function will take a number as argument +and returns the rounded value of this number. + +To use return values, assign them to `variables`: + +```js +let roundedValue = Math.round(1.8) // Here we assign the result of the function call +console.log(roundedValue) // 2 +``` + +The variable `roundedValue` value is the number `2`, the result of the function +call. + +#### Nested function calls + +It is also possible to use the return value of a function directly without using +an intermediary variable.\ +For example we could have written: + +```js +console.log(Math.round(3.2)) // double functions call !!!! woaaaa +``` + +Here we first call `Math.round(3.2)` which returns the number `3` and that will +be passed to `console.log` that will procede to display it. + +### Instructions + +We have prepared a variable `num`. +Just as a warm up, use this variable `num` as `argument` of some `Math` +functions. + +- Declare a `rounded` variable of `num` rounded value. +- Declare a `truncated` variable of `num` truncated value. + +One of the necessary Math function is already used in the lessons examples before the instructions. +Explore the link below to see which others functions the Math object contains in order to find what +you need to complete this exercise. + +### Notions + +- [Math](https://devdocs.io/javascript/global_objects/math) diff --git a/subjects/your-own/README.md b/subjects/your-own/README.md new file mode 100644 index 000000000..c41145834 --- /dev/null +++ b/subjects/your-own/README.md @@ -0,0 +1,5 @@ +## 🌟 your own + +- coding reduce +- coding filter +- coding map