Browse Source

discovery-piscine: add subjects and tests

merge hello-there subject
pull/766/head
Chris 4 years ago
parent
commit
5ff30bcf33
  1. 26
      js/tests/3-directions.json
  2. 14
      js/tests/a-string-of-number.json
  3. 10
      js/tests/access.json
  4. 10
      js/tests/alter-ego.json
  5. 6
      js/tests/an-undefined-future.json
  6. 18
      js/tests/anything-to-declare.json
  7. 14
      js/tests/capitalized.json
  8. 18
      js/tests/cultural-shift.json
  9. 26
      js/tests/cut.json
  10. 14
      js/tests/duplicate.json
  11. 22
      js/tests/griswold-the-blacksmith.json
  12. 14
      js/tests/half-a-million.json
  13. 18
      js/tests/hello-there.json
  14. 6
      js/tests/inequality.json
  15. 26
      js/tests/keep.json
  16. 18
      js/tests/keymaker.json
  17. 14
      js/tests/lines.json
  18. 18
      js/tests/maximus.json
  19. 14
      js/tests/mirror.json
  20. 14
      js/tests/mixed-feelings.json
  21. 10
      js/tests/nested-objects.json
  22. 10
      js/tests/notorious.json
  23. 18
      js/tests/object.json
  24. 14
      js/tests/parenting.json
  25. 10
      js/tests/placeholders.json
  26. 18
      js/tests/pop-art.json
  27. 14
      js/tests/ratchet-clap.json
  28. 6
      js/tests/redeclaration-of-love.json
  29. 18
      js/tests/smooth-operator.json
  30. 10
      js/tests/swapy.json
  31. 26
      js/tests/the-four-seasons.json
  32. 18
      js/tests/the-great-escape.json
  33. 14
      js/tests/the-true-king.json
  34. 10
      js/tests/unchanging.json
  35. 18
      js/tests/wololo.json
  36. 14
      js/tests/words.json
  37. 18
      js/tests/you-spin-me-round.json
  38. 50
      subjects/3-directions/README.md
  39. 15
      subjects/a-string-of-number/README.md
  40. 20
      subjects/access/README.md
  41. 40
      subjects/all-caps/README.md
  42. 55
      subjects/alter-ego/README.md
  43. 20
      subjects/an-undefined-future/README.md
  44. 123
      subjects/anything-to-declare/README.md
  45. 11
      subjects/capitalized/README.md
  46. 3
      subjects/cloning-vs-copying/README.md
  47. 18
      subjects/cultural-shift/README.md
  48. 16
      subjects/cut/README.md
  49. 13
      subjects/duplicate/README.md
  50. 3
      subjects/extremes/README.md
  51. 3
      subjects/frozen-more-about-mutability/README.md
  52. 3
      subjects/go-to-11/README.md
  53. 106
      subjects/griswold-the-blacksmith/README.md
  54. 53
      subjects/half-a-million/README.md
  55. 72
      subjects/hello-there/README.md
  56. 3
      subjects/if-methods/README.md
  57. 12
      subjects/inequality/README.md
  58. 15
      subjects/keep/README.md
  59. 71
      subjects/keymaker/README.md
  60. 45
      subjects/lines/README.md
  61. 23
      subjects/maximus/README.md
  62. 14
      subjects/mirror/README.md
  63. 19
      subjects/mixed-feelings/README.md
  64. 3
      subjects/nested-loops-2/README.md
  65. 3
      subjects/nested-loops-3/README.md
  66. 3
      subjects/nested-loops/README.md
  67. 15
      subjects/nested-objects/README.md
  68. 16
      subjects/notorious/README.md
  69. 81
      subjects/object/README.md
  70. 25
      subjects/parenting/README.md
  71. 34
      subjects/placeholders/README.md
  72. 18
      subjects/pop-art/README.md
  73. 16
      subjects/ratchet-clap/README.md
  74. 31
      subjects/redeclaration-of-love/README.md
  75. 3
      subjects/repeated/README.md
  76. 50
      subjects/seeker-of-truth/README.md
  77. 56
      subjects/smooth-operator/README.md
  78. 53
      subjects/swapy/README.md
  79. 47
      subjects/the-four-seasons/README.md
  80. 41
      subjects/the-great-escape/README.md
  81. 6
      subjects/the-true-king/README.md
  82. 15
      subjects/unchanging/README.md
  83. 3
      subjects/what-else/README.md
  84. 51
      subjects/wololo/README.md
  85. 12
      subjects/words/README.md
  86. 104
      subjects/you-spin-me-round/README.md
  87. 5
      subjects/your-own/README.md

26
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'])"
}
]

14
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')"
}
]

10
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)"
}
]

10
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})"
}
]

6
js/tests/an-undefined-future.json

@ -0,0 +1,6 @@
[
{
"description": "myFuture must be declared but its value undefined",
"code": "equal(myFuture, undefined)"
}
]

18
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}"
}
]

14
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')"
}
]

18
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'])"
}
]

26
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, 'զէըթժիլխծկհձղճմյնշոչպջռսվտրցւփ')"
}
]

14
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 !')"
}
]

22
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'])"
}
]

14
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 /<o|)3'\nlet vault = { '53(.-3T /<o|)3': 500000 }\n// Your code\nequal(loot, 500000)"
},
{
"description": "You must change the value of the vault",
"code": "let secret = '53CR37-k0D3'\nlet vault = { '53CR37-k0D3': '1/2 MM $' }\n// Your code\nif (vault['53CR37-k0D3'] === '1/2 MM $') {\n throw Error('vault value was not changed')\n}"
}
]

18
js/tests/hello-there.json

@ -0,0 +1,18 @@
[
{
"description": "Log a number in the console",
"code": "// If you see this code, it means that you failed the first tests.\n// each tests have it's own code to be tested that will appear if\n// your solution doesn't pass it, it is not here to help you.\n// While sometimes it may clarify the instructions\n// this specific test is complex and will most likely confuse you.\n\n// This is to save all the values that you console.log'd\nconst args = saveArguments(console, 'log')\n\n// This comment below will be replaced by your code\n// Your code\n\n// This is where we check that the value are expected.\n// It's pretty advanced code, you don't have to understand it\n// Do not try to use it for the solution, it will not help you.\nconst typeOfLoggedValues = args.flat().map((v) => 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}"
}
]

6
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}"
}
]

26
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, 'աբգֆուև')"
}
]

18
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')"
}
]

14
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)"
}
]

18
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)"
}
]

14
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')"
}
]

14
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}"
}
]

10
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')"
}
]

10
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}"
}
]

18
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')"
}
]

14
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)"
}
]

10
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`)"
}
]

18
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'])"
}
]

14
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)"
}
]

6
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 !!')"
}
]

18
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)"
}
]

10
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'])"
}
]

26
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)"
}
]

18
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}"
}
]

14
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')"
}
]

10
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}"
}
]

18
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)"
}
]

14
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])"
}
]

18
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)"
}
]

50
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

15
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é

20
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`

40
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

55
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

20
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

123
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 !

11
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 !

3
subjects/cloning-vs-copying/README.md

@ -0,0 +1,3 @@
## 🌟 Cloning vs Copying
### Instructions

18
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)

16
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)

13
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 !`.

3
subjects/extremes/README.md

@ -0,0 +1,3 @@
## extremes
find the bigest and smallest number of the list

3
subjects/frozen-more-about-mutability/README.md

@ -0,0 +1,3 @@
## 🌟 frozen: more about mutability
### Instructions

3
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)

106
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:
<!-- prettier-ignore-start -->
```js
if (age > 48) {
// <- without indentation ! bad bad ! unreadable !!
console.log('You are over 48 years old')
}
```
<!-- prettier-ignore-end -->
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

53
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

72
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

3
subjects/if-methods/README.md

@ -0,0 +1,3 @@
## if + `.methods()`
startsWith / endWith

12
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.

15
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)

71
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

45
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)

23
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.

14
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)

19
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`

3
subjects/nested-loops-2/README.md

@ -0,0 +1,3 @@
## nested loops 2
pyramid centred (padStart, padEnd)

3
subjects/nested-loops-3/README.md

@ -0,0 +1,3 @@
## 🌟 nested loops 3
diamon (pyramid + reversed pyramid)

3
subjects/nested-loops/README.md

@ -0,0 +1,3 @@
## nested loops !
pyramid 1

15
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`

16
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

81
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

25
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

34
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.

18
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)

16
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)

31
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.

3
subjects/repeated/README.md

@ -0,0 +1,3 @@
## repeated
repeat a string N times, without using the method

50
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()
}
```

56
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)

53
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 !

47
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)

41
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

6
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'`

15
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.

3
subjects/what-else/README.md

@ -0,0 +1,3 @@
## What else ?
if / else + includes?

51
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`

12
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)

104
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)

5
subjects/your-own/README.md

@ -0,0 +1,5 @@
## 🌟 your own
- coding reduce
- coding filter
- coding map
Loading…
Cancel
Save