Browse Source

update discovery-piscine subjects and tests

pull/779/head
Clement Denis 3 years ago
parent
commit
0e67e834e5
  1. 20
      js/tests/a-new-purpose.json
  2. 20
      js/tests/a-winning-argument.json
  3. 24
      js/tests/give-it-a-rest.json
  4. 34
      js/tests/happy.json
  5. 24
      js/tests/level-up.json
  6. 4
      js/tests/phant0m-writ3r.json
  7. 20
      js/tests/to-infinity-and-beyond.json
  8. 24
      js/tests/two-can-play-that-game.json
  9. 24
      js/tests/what-is-my-purpose.json
  10. 12
      js/tests/you-pass-butter.json
  11. 2
      subjects/a-new-purpose/README.md
  12. 8
      subjects/a-winning-argument/README.md
  13. 33
      subjects/access/README.md
  14. 14
      subjects/extremes/README.md
  15. 18
      subjects/give-it-a-rest/README.md
  16. 42
      subjects/go-to-11/README.md
  17. 16
      subjects/happy/README.md
  18. 30
      subjects/two-can-play-that-game/README.md
  19. 29
      subjects/what-is-my-purpose/README.md
  20. 31
      subjects/you-pass-butter/README.md

20
js/tests/a-new-purpose.json

@ -1,26 +1,26 @@
[
{
"description": "add2, sub2, mult2 and div2 are defined and are functions",
"code": "if (typeof add2 === 'undefined') {\n throw Error(\n `You didn't even define the function add2... make it better! reread the lesson...`,\n )\n}\nif (typeof add2 != 'function') {\n throw Error('add2 must be a function')\n}\n\nif (typeof sub2 === 'undefined') {\n throw Error(\n `You didn't even define the function sub2... make it better! reread the lesson...`,\n )\n}\nif (typeof sub2 != 'function') {\n throw Error('sub2 must be a function')\n}\n\nif (typeof mult2 === 'undefined') {\n throw Error(\n `You didn't even define the function mult2... make it better! reread the lesson...`,\n )\n}\nif (typeof mult2 != 'function') {\n throw Error('mult2 must be a function')\n}\n\nif (typeof div2 === 'undefined') {\n throw Error(\n `You didn't even define the function div2... make it better! reread the lesson...`,\n )\n}\nif (typeof div2 != 'function') {\n throw Error('div2 must be a function')\n}"
"description": "add2 is defined and are functions",
"code": "equal(typeof add2, 'function')"
},
{
"description": "add2, sub2, mult2 and div2 have 2 arguments",
"code": "if (add2.length != 2) {\n throw Error('You need 2 arguments for this function!(add2)')\n}\nif (sub2.length != 2) {\n throw Error('You need 2 arguments for this function!(sub2)')\n}\nif (mult2.length != 2) {\n throw Error('You need 2 arguments for this function!(mult2)')\n}\nif (div2.length != 2) {\n throw Error('You need 2 arguments for this function!(div2)')\n}"
"description": "add2 takes 2 arguments",
"code": "equal(add2.length, 2)"
},
{
"description": "add2 returns the right results",
"code": "equal(add2(1, 1), 2)\nequal(add2(1, 2), 3)\nequal(add2(2, 2), 4)\nequal(add2(2, 3), 5)"
},
{
"description": "sub2 returns the right results",
"code": "equal(sub2(1, 1), 0)\nequal(sub2(2, 1), 1)\nequal(sub2(3, 1), 2)\nequal(sub2(4, 1), 3)"
"description": "sub2 is defined and are functions",
"code": "equal(typeof sub2, 'function')"
},
{
"description": "mult2 returns the right results",
"code": "equal(mult2(1, 1), 1)\nequal(mult2(1, 2), 2)\nequal(mult2(2, 2), 4)\nequal(mult2(2, 3), 6)"
"description": "sub2 takes 2 arguments",
"code": "equal(sub2.length, 2)"
},
{
"description": "div2 returns the right results",
"code": "equal(div2(1, 1), 1)\nequal(div2(2, 1), 2)\nequal(div2(2, 2), 1)\nequal(div2(6, 2), 3)"
"description": "sub2 returns the right results",
"code": "equal(sub2(1, 1), 0)\nequal(sub2(2, 1), 1)\nequal(sub2(3, 1), 2)\nequal(sub2(-4, -7), 3)"
}
]

20
js/tests/a-winning-argument.json

@ -1,26 +1,30 @@
[
{
"description": "battleCry is a defined and is a function",
"code": "if (typeof battleCry === 'undefined') {\n throw Error(\n `You didn't even define the function battleCry... make it better! reread the lesson...`,\n )\n}\n\nif (typeof battleCry != 'function') {\n throw Error('battleCry must be a function')\n}"
"description": "battleCry is defined and is a function",
"code": "equal(typeof battleCry, 'function')"
},
{
"description": "secretOrders is a defined and is a function",
"code": "if (typeof secretOrders === 'undefined') {\n throw Error(\n `You didn't even define the function secretOrders... make it better! reread the lesson...`,\n )\n}\n\nif (typeof secretOrders != 'function') {\n throw Error('secretOrders must be a function')\n}"
"description": "secretOrders is defined and is a function",
"code": "equal(typeof secretOrders, 'function')"
},
{
"description": "battleCry has one and only one argument",
"code": "if (battleCry.length != 1) {\n throw Error('You must use 1 argument for this function, and only one!')\n}"
"code": "equal(battleCry.length, 1)"
},
{
"description": "secretOrders has one and only one argument",
"code": "if (secretOrders.length != 1) {\n throw Error('You must use 1 argument for this function, and only one!')\n}"
"code": "equal(secretOrders.length, 1)"
},
{
"description": "battleCry shouts properly",
"code": "const args = saveArguments(console, 'log')\nlet orders = {\n shouted: ['attack!', 'you shall not pass!', 'for the horde!'],\n secrets: ['ExEcutE Order 66', 'SILENCE', 'This Is The WAY'],\n}\n\n// Your code\n\norders.shouted.map((el) => battleCry(el))\n\nconst loggedValues = args.flat().join(' ')\nif (!loggedValues.includes('ATTACK!')) {\n throw Error(`battleCry('attack!') is not SHOUTING: ATTACK!`)\n}\nif (!loggedValues.includes('YOU SHALL NOT PASS!')) {\n throw Error(\n `battleCry(you shall not pass!) is not SHOUTING: YOU SHALL NOT PASS!`,\n )\n}\nif (!loggedValues.includes('FOR THE HORDE!')) {\n throw Error(`battleCry('for the horde!') is not SHOUTING: FOR THE HORDE!`)\n}"
"code": "const args = saveArguments(console, 'log')\n// Your code\n\nbattleCry('attack')\nbattleCry('you shall not pass!')\n\nequal(args.flat(), ['ATTACK', 'YOU SHALL NOT PASS!'])"
},
{
"description": "secretOrders whispers properly",
"code": "const args = saveArguments(console, 'log')\nlet orders = {\n shouted: ['attack!', 'you shall not pass!', 'for the horde!'],\n secrets: ['ExEcutE Order 66', 'SILENCE', 'This Is The WAY'],\n}\n\n// Your code\n\norders.secrets.map((el) => secretOrders(el))\n\nconst loggedValues = args.flat().join(' ')\nif (!loggedValues.includes('execute order 66')) {\n throw Error(\n `secretOrders('ExEcutE Order 66') is not whispering: execute order 66 `,\n )\n}\nif (!loggedValues.includes('silence')) {\n throw Error(`secretOrders('SILENCE') is not whispering: silence `)\n}\nif (!loggedValues.includes('this is the way')) {\n throw Error(\n `secretOrders('This Is The WAY') is not whispering: this is the way `,\n )\n}"
"code": "const args = saveArguments(console, 'log')\n\n// Your code\n\nsecretOrders('ExEcutE Order 66')\nsecretOrders('SILENCE')\n\nequal(args.flat(), ['execute order 66', 'silence'])"
},
{
"description": "We can call both functions",
"code": "const args = saveArguments(console, 'log')\n\n// Your code\n\nsecretOrders('This Is The WAY')\nbattleCry('for the horde !')\n\nequal(args.flat(), ['this is the way', 'FOR THE HORDE !'])"
}
]

24
js/tests/give-it-a-rest.json

@ -1,22 +1,26 @@
[
{
"description": "addAll, subAll, multAll and divAll are defined and are functions",
"code": "if (typeof addAll === 'undefined') {\n throw Error(\n `You didn't even define the function addAll... make it better! reread the lesson...`,\n )\n}\nif (typeof addAll != 'function') {\n throw Error('addAll must be a function')\n}\n\nif (typeof subAll === 'undefined') {\n throw Error(\n `You didn't even define the function subAll... make it better! reread the lesson...`,\n )\n}\nif (typeof subAll != 'function') {\n throw Error('subAll must be a function')\n}\n\nif (typeof multAll === 'undefined') {\n throw Error(\n `You didn't even define the function multAll... make it better! reread the lesson...`,\n )\n}\nif (typeof multAll != 'function') {\n throw Error('multAll must be a function')\n}\n\nif (typeof divAll === 'undefined') {\n throw Error(\n `You didn't even define the function divAll... make it better! reread the lesson...`,\n )\n}\nif (typeof divAll != 'function') {\n throw Error('divAll must be a function')\n}"
"description": "countArgs is defined and are functions",
"code": "equal(typeof countArgs, 'function')"
},
{
"description": "addAll returns the right results",
"code": "equal(addAll(1, 1), 2)\nequal(addAll(1, 2, 3), 6)\nequal(addAll(2, 2, 4, 10), 18)\nequal(addAll(2, 3, 3, 5, 5, 10), 28)"
"description": "countArgs returns the right results for 2 arguments",
"code": "equal(countArgs(1, 1), 2)"
},
{
"description": "subAll returns the right results",
"code": "equal(subAll(1, 1), 0)\nequal(subAll(2, 1, 1, -1), 1)\nequal(subAll(10, 3, 1, 4), 2)\nequal(subAll(11, 4, 1, 3, 3, 3), -3)"
"description": "countArgs returns the right results for 3 arguments",
"code": "equal(countArgs(1, 2, 3), 3)"
},
{
"description": "multAll returns the right results",
"code": "equal(multAll(1, 1), 1)\nequal(multAll(1, 2, 10), 20)\nequal(multAll(2, 2, 10, 10), 400)\nequal(multAll(2, 3, -2, 10, 10), -1200)"
"description": "countArgs returns the right results for 4 arguments",
"code": "equal(countArgs(2, 2, 4, 10), 4)"
},
{
"description": "divAll returns the right results",
"code": "equal(divAll(1, 1), 1)\nequal(divAll(2, 1, 1), 2)\nequal(divAll(100, 2, 2, 5), 5)\nequal(divAll(1000, 10, 5, 4, 1), 5)"
"description": "countArgs returns the right results for 6 arguments",
"code": "equal(countArgs(2, 3, 3, 5, 5, 10), 6)"
},
{
"description": "countArgs can count a lot of arguments",
"code": "equal(countArgs(...Array(999).fill()), 999)"
}
]

34
js/tests/happy.json

@ -1,26 +1,46 @@
[
{
"description": "happy is defined and is a function",
"code": "if (typeof happy === 'undefined') {\n throw Error(\n `You didn't even define the function happy... make it better! reread the lesson...`,\n )\n}\nif (typeof happy != 'function') {\n throw Error('happy must be a function')\n}"
"code": "equal(typeof happy, 'function')"
},
{
"description": "happy has 1 argument",
"code": "if (happy.length != 1) {\n throw Error('You need 1 argument for this function!')\n}"
"code": "equal(happy.length, 1)"
},
{
"description": "happy is smiling right.",
"code": "equal(happy('Are you happy?'), true)\nequal(happy('Happy?'), true)\nequal(happy('Are you sad?'), false)\nequal(happy('happy!'), false)\nequal(happy('Happy! are we not?'), true)"
"description": "very happy.",
"code": "equal(happy('Are you happy ?'), true)"
},
{
"description": "very happy.",
"code": "equal(happy('Happy ?'), true)"
},
{
"description": "very happy.",
"code": "equal(happy('Happy ! are we not ?'), true)"
},
{
"description": "not happy.",
"code": "equal(happy('Are you sad ?'), false)"
},
{
"description": "not happy.",
"code": "equal(happy('happy !'), false)"
},
{
"description": "not happy.",
"code": "equal(happy('Was I happy ? nope.'), false)"
},
{
"description": "happy has no curly braces {}.",
"code": "if (happy.toString().includes('{')) {\n throw Error('No curly braces {} ! ')\n}\nif (happy.toString().includes('}')) {\n throw Error('No curly braces {} ! ')\n}"
"code": "if (/\\{.*\\}/.test(happy)) {\n throw Error('No curly braces {} ! ')\n}"
},
{
"description": "happy has no keyword return.",
"code": "if (happy.toString().includes('return')) {\n throw Error('No keyword return allowed ! ')\n}"
"code": "if (String(happy).includes('return')) {\n throw Error('No keyword return allowed ! ')\n}"
},
{
"description": "happy has no keyword if.",
"code": "if (happy.toString().includes('if')) {\n throw Error('No keyword if allowed ! ')\n}"
"code": "if (String(happy).includes('if')) {\n throw Error('No keyword if allowed ! ')\n}"
}
]

24
js/tests/level-up.json

@ -1,14 +1,30 @@
[
{
"description": "shaker is a defined and is a function",
"code": "if (typeof shaker === 'undefined') {\n throw Error(\n `You didn't even define the function shaker... make it better! reread the lesson...`,\n )\n}\n\nif (typeof shaker != 'function') {\n throw Error('shaker must be a function')\n}"
"description": "shaker is defined and is a function",
"code": "equal(typeof shaker, 'function')"
},
{
"description": "shaker has 3 arguments",
"code": "if (shaker.length != 3) {\n throw Error('You need 3 arguments for this function!')\n}"
"code": "equal(shaker.length, 3)"
},
{
"description": "shaker can make a cocktail.",
"code": "equal(shaker(1, 'strawberry', true), '1 strawberry cocktail')"
},
{
"description": "shaker can make a milkshake.",
"code": "equal(shaker(1, 'strawberry', false), '1 strawberry milkshake')"
},
{
"description": "shaker can make multiple cocktails.",
"code": "equal(shaker(7, 'banana', true), '7 banana cocktails')"
},
{
"description": "shaker can make multiple milkshakes.",
"code": "equal(shaker(22, 'banana', false), '22 banana milkshakes')"
},
{
"description": "shaker is shakin it right.",
"code": "equal(shaker(1, 'strawberry', true), '1 strawberry cocktail')\nequal(shaker(1, 'vanilla', true), '1 vanilla cocktail')\nequal(shaker(1, 'mango', true), '1 mango cocktail')\nequal(shaker(1, 'strawberry', false), '1 strawberry milkshake')\n\nequal(shaker(2, 'banana', true), '2 banana cocktails')\nequal(shaker(2, 'chocolate', false), '2 chocolate milkshakes')\nequal(shaker(2, 'vanilla', false), '2 vanilla milkshakes')\nequal(shaker(2, 'strawberry', false), '2 strawberry milkshakes')"
"code": "equal(shaker(1, 'vanilla', true), '1 vanilla cocktail')\nequal(shaker(1, 'mango', true), '1 mango cocktail')\nequal(shaker(2, 'banana', true), '2 banana cocktails')\nequal(shaker(2, 'chocolate', false), '2 chocolate milkshakes')\nequal(shaker(2, 'vanilla', false), '2 vanilla milkshakes')\nequal(shaker(2, 'strawberry', false), '2 strawberry milkshakes')"
}
]

4
js/tests/phant0m-writ3r.json

@ -18,5 +18,9 @@
{
"description": "Tests with 'caution'",
"code": "let word = 'caution'\nconst args = saveArguments(console, 'log')\n\n// Your code\n\nequal(args[0], ['caution'])"
},
{
"description": "Tests with 'alegation'",
"code": "let word = 'alegation'\nconst args = saveArguments(console, 'log')\n\n// Your code\n\nequal(args, [])"
}
]

20
js/tests/to-infinity-and-beyond.json

@ -1,6 +1,22 @@
[
{
"description": "Not implemented",
"code": "throw Error('oops')"
"description": "Weak candidates must stay on earth",
"code": "let candidate = { noFamily: true, physicalAptitudes: 5 }\nconst args = saveArguments(console, 'log')\n\n// Your code\n\nequal(args[0], ['earth'])"
},
{
"description": "Strong candadidates without families can go on mars",
"code": "let candidate = { noFamily: true, physicalAptitudes: 99 }\nconst args = saveArguments(console, 'log')\n\n// Your code\n\nequal(args[0], ['mars'])"
},
{
"description": "Strong candadidates with a family can go to the moon",
"code": "let candidate = { noFamily: false, physicalAptitudes: 87 }\nconst args = saveArguments(console, 'log')\n\n// Your code\n\nequal(args[0], ['moon'])"
},
{
"description": "Even barely strong enough candidates can make it",
"code": "let candidate = { noFamily: false, physicalAptitudes: 80 }\nconst args = saveArguments(console, 'log')\n\n// Your code\n\nequal(args[0], ['moon'])"
},
{
"description": "But almost strong enough candidates can not",
"code": "let candidate = { noFamily: true, physicalAptitudes: 79 }\nconst args = saveArguments(console, 'log')\n\n// Your code\n\nequal(args[0], ['earth'])"
}
]

24
js/tests/two-can-play-that-game.json

@ -1,26 +1,26 @@
[
{
"description": "duos is a defined and is a function",
"code": "if (typeof duos === 'undefined') {\n throw Error(\n `You didn't even define the function duos... make it better! reread the lesson...`,\n )\n}\n\nif (typeof duos != 'function') {\n throw Error('duos must be a function')\n}"
"description": "duos is defined and is a function",
"code": "equal(typeof duos, 'function')"
},
{
"description": "duos has two arguments",
"code": "if (duos.length != 2) {\n throw Error('You need two arguments for this function!')\n}"
"description": "duos takes two arguments",
"code": "equal(duos.length, 2)"
},
{
"description": "duos combines properly",
"code": "const args = saveArguments(console, 'log')\nlet combinations2 = [\n ['Batman', 'Robin'],\n ['Pinky', 'The Brain'],\n ['Bonnie', 'Clyde'],\n ['Mr.', 'Mrs.Smith'],\n]\n\n// Your code\n\ncombinations2.map((el) => duos(el[0], el[1]))\n\nconst loggedValues = args.flat().join(' ')\nif (!loggedValues.includes('Batman and Robin!')) {\n throw Error(`duos('Batman', 'Robin') is not combining: Batman and Robin!`)\n}\nif (!loggedValues.includes('Pinky and The Brain!')) {\n throw Error(\n `duos('Pinky', 'The Brain') is not combining: Pinky and The Brain!`,\n )\n}\nif (!loggedValues.includes('Bonnie and Clyde!')) {\n throw Error(`duos('Bonnie', 'Clyde') is not combining: Bonnie and Clyde!`)\n}\nif (!loggedValues.includes('Mr. and Mrs.Smith!')) {\n throw Error(`duos('Mr.', 'Mrs.Smith') is not combining: Mr. and Mrs.Smith!`)\n}"
"description": "duos logs the expected result",
"code": "const args = saveArguments(console, 'log')\n\n// Your code\n\nduos('Batman', 'Robin')\nduos('Pinky', 'The Brain')\nduos('Bonnie', 'Clyde')\nduos('Mr.', 'Mrs.Smith')\n\nequal(\n args.map(arg => arg.join(' ')),\n [\n 'Batman and Robin !',\n 'Pinky and The Brain !',\n 'Bonnie and Clyde !',\n 'Mr. and Mrs.Smith !',\n ],\n)"
},
{
"description": "duosWork is a defined and is a function",
"code": "if (typeof duosWork === 'undefined') {\n throw Error(\n `You didn't even define the function duosWork... make it better! reread the lesson...`,\n )\n}\n\nif (typeof duosWork != 'function') {\n throw Error('duosWork must be a function')\n}"
"description": "duosWork is defined and is a function",
"code": "equal(typeof duosWork, 'function')"
},
{
"description": "duosWork has three arguments",
"code": "if (duosWork.length != 3) {\n throw Error('You need three arguments for this function!')\n}"
"description": "duosWork takes three arguments",
"code": "equal(duosWork.length, 3)"
},
{
"description": "duosWork combines properly",
"code": "const args = saveArguments(console, 'log')\nlet combinations3 = [\n ['Batman', 'Robin', 'protect Gotham'],\n ['Pinky', 'The Brain', 'want to conquer the world'],\n ['Bonnie', 'Clyde', 'escape the Police'],\n ['Mr.', 'Mrs.Smith', 'are the greatest spy couple'],\n]\n\n// Your code\n\ncombinations3.map((el) => duosWork(el[0], el[1], el[2]))\n\nconst loggedValues = args.flat().join(' ')\nif (!loggedValues.includes('Batman and Robin protect Gotham!')) {\n throw Error(\n `duosWork('Batman', 'Robin', 'protect Gotham') is not combining: Batman and Robin protect Gotham!`,\n )\n}\nif (!loggedValues.includes('Pinky and The Brain want to conquer the world!')) {\n throw Error(\n `duosWork('Pinky', 'The Brain', 'want to conquer the world') is not combining: Pinky and The Brain want to conquer the world!`,\n )\n}\nif (!loggedValues.includes('Bonnie and Clyde escape the Police!')) {\n throw Error(\n `duosWork('Bonnie', 'Clyde', 'escape the Police') is not combining: Bonnie and Clyde escape the Police!`,\n )\n}\nif (!loggedValues.includes('Mr. and Mrs.Smith are the greatest spy couple!')) {\n throw Error(\n `duosWork('Mr.', 'Mrs.Smith', 'are the greatest spy couple') is not combining: Mr. and Mrs.Smith are the geatest spy couple!`,\n )\n}"
"description": "duosWork logs the expected result",
"code": "const args = saveArguments(console, 'log')\n\n// Your code\n\nduosWork('Batman', 'Robin', 'protect Gotham')\nduosWork('Pinky', 'The Brain', 'want to conquer the world')\nduosWork('Bonnie', 'Clyde', 'escape the Police')\nduosWork('Mr.', 'Mrs.Smith', 'are the greatest spy couple')\n\nequal(\n args.map(arg => arg.join(' ')),\n [\n 'Batman and Robin protect Gotham !',\n 'Pinky and The Brain want to conquer the world !',\n 'Bonnie and Clyde escape the Police !',\n 'Mr. and Mrs.Smith are the greatest spy couple !',\n ],\n)"
}
]

24
js/tests/what-is-my-purpose.json

@ -1,26 +1,22 @@
[
{
"description": "whatIsMyPurpose is defined and is a function",
"code": "let dialogue = {\n myQuestion: 'What is my purpose?',\n \"Rick's answer\": 'You pass butter.',\n}\n\n// Your code\n\nif (typeof whatIsMyPurpose === 'undefined') {\n throw Error(\n `You didn't even define the function whatIsMyPurpose... make it better! reread the lesson...`,\n )\n}\n\nif (typeof whatIsMyPurpose != 'function') {\n throw Error('whatIsMyPurpose must be a function')\n}"
"description": "ask is defined and is a function",
"code": "equal(typeof ask, 'function')"
},
{
"description": "theAnswer is defined and is a function",
"code": "let dialogue = {\n myQuestion: 'What is my purpose?',\n \"Rick's answer\": 'You pass butter.',\n}\n\n// Your code\n\nif (typeof theAnswer === 'undefined') {\n throw Error(\n `You didn't even define the function theAnswer... make it better! reread the lesson...`,\n )\n}\n\nif (typeof theAnswer != 'function') {\n throw Error('theAnswer must be a function')\n}"
"description": "reply is defined and is a function",
"code": "equal(typeof reply, 'function')"
},
{
"description": "whatIsMyPurpose has no arguments",
"code": "let dialogue = {\n myQuestion: 'What is my purpose?',\n \"Rick's answer\": 'You pass butter.',\n}\n\n// Your code\n\nif (whatIsMyPurpose.length > 0) {\n throw Error('No arguments allowed for this function! You do not need them!')\n}"
"description": "ask works and is called",
"code": "const args = saveArguments(console, 'log')\n\n// Your code\n\nequal(args[0], ['What is my purpose ?'])"
},
{
"description": "theAnswer has no arguments",
"code": "let dialogue = {\n myQuestion: 'What is my purpose?',\n \"Rick's answer\": 'You pass butter.',\n}\n\n// Your code\n\nif (theAnswer.length > 0) {\n throw Error('No arguments allowed for this function! You do not need them!')\n}"
"description": "reply works and is called too",
"code": "const args = saveArguments(console, 'log')\n\n// Your code\n\nequal(args, [['What is my purpose ?'], ['You pass butter.']])"
},
{
"description": "whatIsMyPurpose works and is called",
"code": "const args = saveArguments(console, 'log')\nlet dialogue = {\n myQuestion: 'What is my purpose?',\n \"Rick's answer\": 'You pass butter.',\n}\n\n// Your code\n\nwhatIsMyPurpose()\n\nconst loggedValues = args.flat().join(' ')\nif (!loggedValues.includes('What is my purpose?')) {\n throw Error('you must log the value of the key: myQuestion')\n}\nconst functionCalls = args.flat().filter((el) => el === 'What is my purpose?')\n .length\nif (functionCalls != 2) {\n throw Error(`you must call the function whatIsMyPurpose once\"`)\n}"
},
{
"description": "theAnswer works and is called",
"code": "const args = saveArguments(console, 'log')\nlet dialogue = {\n myQuestion: 'What is my purpose?',\n \"Rick's answer\": 'You pass butter.',\n}\n\n// Your code\n\ntheAnswer()\n\nconst loggedValues = args.flat().join(' ')\nif (!loggedValues.includes('You pass butter.')) {\n throw Error(`you must log the value of the key: \"Rick's answer\"`)\n}\nconst functionCalls = args.flat().filter((el) => el === 'You pass butter.')\n .length\nif (functionCalls != 2) {\n throw Error(`you must call the function theAnswer once\"`)\n}"
"description": "calling reply and ask again relog the text.",
"code": "const args = saveArguments(console, 'log')\n\n// Your code\n\nequal(args[1], ['You pass butter.'])"
}
]

12
js/tests/you-pass-butter.json

@ -1,14 +1,14 @@
[
{
"description": "passButter is a defined and is a function",
"code": "if (typeof passButter === 'undefined') {\n throw Error(\n `You didn't even define the function passButter... make it better! reread the lesson...`,\n )\n}\n\nif (typeof passButter != 'function') {\n throw Error('passButter must be a function')\n}"
"description": "passButter is defined and is a function",
"code": "equal(typeof passButter, 'function')"
},
{
"description": "passButter has no arguments",
"code": "if (passButter.length != 0) {\n throw Error('You need no arguments for this function!')\n}"
"description": "passButter returns The butter properly",
"code": "equal(passButter(), 'The butter')"
},
{
"description": "passButter returns The butter properly",
"code": "// Your code\n\nlet theTable = passButter()\n\nif (theTable != 'The butter') {\n throw Error(`passButter() did not return 'The butter'`)\n}"
"description": "calling passButter mulitple time should always return the butter",
"code": "equal(\n [passButter(), passButter(), passButter()],\n ['The butter', 'The butter', 'The butter'],\n)"
}
]

2
subjects/a-new-purpose/README.md

@ -49,5 +49,3 @@ Define the functions :
- `add2` which adds two arguments and returns the result.
- `sub2` which substract two arguments and returns the result.
- `mult2` which substract two arguments and returns the result.
- `div2` which divides two arguments and returns the result.

8
subjects/a-winning-argument/README.md

@ -7,7 +7,7 @@ always in between parens `()`.
Let's use the same examples that we used for function calls:
Remember this example of function call?:
Remember this example of function call ?
```js
// ↙ method
@ -16,7 +16,7 @@ console.log('Hello There !') //<-
// the argument of console.log()
```
or these ones?:
or these ones ?
```js
let roundedValue = Math.round(1.8) // The number 1.8 is the arg
@ -27,7 +27,7 @@ We are now going to adapt `myFirstFuntion` so that it takes one argument :
`arg1`.
```js
let myFirstFunction = (arg1) => {
let myFirstFunction = arg1 => {
//<-arg1 is inputed in between the parens
console.log(arg1) // arg1 can be use inside the scope of the function
// ↖ arg1 is "transfered" to be the arg of console.log()
@ -50,7 +50,7 @@ myFirstFunction('and another one') // "and another one"
myFirstFunction('and one more') // "and one more"
```
> waste no more time arguing about what a good man should be. Be one.
> Waste no more time arguing about what a good person should be. Be one.
>
> - Marcus Aurelius

33
subjects/access/README.md

@ -7,6 +7,39 @@ Now that we know how to define objects, let's start to use them
Let's start with getting values from them. Well, turns out you already have been
doing it a lot, remember `console.log` ?
The `.` here is *accessing* the property `log` from the `console` object.
Taking the previous example `transaction` object, we can access properties
from it using `.` same way we got the `log` function:
```js
let transaction = {
currency: 'EURO',
amount: 77.5,
cashPayment: false,
}
console.log(transaction) // Will log the whole transaction
console.log(transaction.amount) // will only log the amount of the transaction
```
Accessing a property with `.` only give you it's value, and
because it is a value you can use it like any other values:
```js
let taxes = 1.2 // let's define 20% taxes
let transaction = {
currency: 'EURO',
amount: 77.5,
cashPayment: false,
}
const totalWithTaxes = transaction.amount * taxes
console.log(totalWithTaxes) // will log 93 (77.5 * 1.2)
```
### Instructions
We will provide a `human` variable of type object just like the one you did in

14
subjects/extremes/README.md

@ -1,3 +1,13 @@
## extremes
## Extremes
find the bigest and smallest number of the list
### Instructions
Create a function `extreme` that given an array of number find the bigest and
smallest number of the array
**Examples:**
```js
extreme([-1, 0, 10, 5]) // -> { bigest: 10, smallest: -1 }
extreme([22, 7, 32, 99, 54]) // -> { bigest: 99, smallest: 7 }
```

18
subjects/give-it-a-rest/README.md

@ -1,23 +1,17 @@
## 🌟 Give it a ...rest
### Notions
- [devdocs.io/functions/rest_parameters](https://devdocs.io/javascript/functions/rest_parameters)
- [devdocs.io/javascript/global_objects/array/reduce](https://devdocs.io/javascript/global_objects/array/reduce)
### Instructions
You are now a butter passer, calculator, and barttender all-in-one robot. You
want to keep on improving but you can feel like your memory capacities are
reaching their limits. You will now try to improve what you aready have.
Declare the function `addAll` which will will return the sum of all the
arguments it recieves. Examples:
Declare the function `countArgs` which will return the number of argument it
recieved. Examples:
```js
console.log(addAll(1)) //1
console.log(addAll(1, 10)) //11
console.log(addAll(1, 10, 100)) //111
console.log(countArgs(1)) // 1
console.log(countArgs(1, 10)) // 2
console.log(countArgs(1, 10, 100)) // 3
// etc...
```
You will then do exactly the same for `subAll`, `MultAll` and `divAll`.

42
subjects/go-to-11/README.md

@ -1,3 +1,45 @@
## Go to 11
### Looping with the `while` keyword
Loops are one of the last missing basic blocks of programing left to learn,
let's see it in action:
```js
while (count < 30) {
// Code to be repeated here
}
```
As you can see, it is exactly like an `if`, we have a scope `{}` and a
`(condition)` just a new keyword.
Unlike the `if` however, the code inside the scope will be executed as long as
the condition is `true`
It is easy to get stuck in an never ending loop as if your condition is never
`false` you will always be stuck in a loop
As such it is common to have some kind of iteration inside our looping code:
```js
while (count < 30) {
count = count + 1
}
```
Now everytime our code is executed, the value of `count` will be `incremented`
by `1`, until it reach `30` and stop.
> If your code is stuck in an infinite loop, you can do a Ctrl+C shortcut in the
> terminal to interrupt the code
### Instructions
Write a function `goTo11` that takes a `start` number argument and call
`console.log` on each numbers from the `start` (included) up to and including
`11`.
If the `start` is higher than `11` your function must do nothing.
[These go to Eleven... — "This is Spinal Tap" (1984)](https://www.youtube.com/watch?v=hW008FcKr3Q)

16
subjects/happy/README.md

@ -1,16 +1,16 @@
## 🌟 Happy?
## 🌟 Happy ?
### Notions
[devdocs.io/javascript/global_objects/string/includes](https://devdocs.io/javascript/global_objects/string/includes)
[developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Conditional_Operator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Conditional_Operator)
- [Includes](https://devdocs.io/javascript/global_objects/string/includes)
- [Conditional (ternary) Operator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Conditional_Operator)
### Instructions
With all the you know now you are not a truly happy, efficient and independent
With all that you know now you are not a truly happy, efficient and independent
robot.
You have decided that if someone ask you the question `Are you happy?` or
You have decided that if someone ask you the question `Are you happy ?` or
questions that includes the word `happy` you will always says that it is `true`.
To do so you will declare the function `happy` which takes only one argument and
returns a boolean.
@ -18,10 +18,10 @@ returns a boolean.
Examples:
```js
console.log(happy('Are you happy?')) // true
console.log(happy('Happy?')) // true
console.log(happy('Are you happy ?')) // true
console.log(happy('Happy ?')) // true
console.log(happy('Are you happy!')) // false -> this is not a question
console.log(happy('Are you sad?')) // false -> wrong question
console.log(happy('Are you sad ?')) // false -> wrong question
```
Any other requests will be denied with a `false`. (if it is not a question of if

30
subjects/two-can-play-that-game/README.md

@ -1,22 +1,12 @@
## Two can play that game
### Arguments (Continued)
### More Arguments
We have seen how to add one argument to the a function, We are now going to see
how to add two (or more).
Remember when `arg1` was added in the parens `()`?
```js
let myFirstFunction = (arg1) => {
console.log(arg1)
}
// Now we call the function
myFirstFunction('using my first arg') // "using my first arg"
```
Well now, all we need to do to add a second argument `arg2` is to add a comma
`,` after `arg1` and then add `arg2`.
All we need to do to add a second argument `arg2` is to add a comma `,` after
`arg1` and then add `arg2`.
```js
let myFirstFunction = (arg1, arg2) => {
@ -65,17 +55,17 @@ myFirstFunction('Europe', 'France', 'Paris', '30°C')
### Instructions
You want to conquer the world! (of entertainment).
You want to conquer the world! _(of entertainment)_.
In this exercise you will have to declare the function `duos`.
This function will take two arguments and will log them together with an `and`
and a `!`
and an `!`
Example: If the `arg1` is `Batman` and `arg2` is `Robin`, the fonction should
log : `Batman and Robin!`
> Example: calling: `duos('Batman', 'Robin')` should log : `Batman and Robin !`
You will then declare the function `duosWork`. This function will take three
arguments and will log them togethers as in the example below. Example: If the
`arg1` is `Batman`, the`arg2` is `Robin`, and the `arg3` is `protect Gotham`.
the fonction should log : `Batman and Robin protect Gotham!`
arguments and will log them togethers as in the example below.
> Example: calling: `duosWork('Batman', 'Robin', 'protect Gotham')` should log :
> `Batman and Robin protect Gotham !`

29
subjects/what-is-my-purpose/README.md

@ -1,12 +1,10 @@
## What is my purpose?
## What is my purpose ?
![robot](https://cdn.discordapp.com/attachments/489466992286498816/828181029772197888/butter-purpose.png)
### Remember Methods?
You have seen how to call functions that were stored in object properties.
Remember this example of function call?:
Remember this example of function call ?
```js
// ↙ identifier, like variables
@ -14,19 +12,19 @@ console.log('Hello There !') // <- function call happening here
// ↖ open paren + argument + close paren
```
or these ones?:
or these ones:
```js
let roundedValue = Math.round(1.8) // another function call happening here
console.log(roundedValue) // and another one here
```
There, we saw how to call and use _"pre-declared"_ functions.
There, we saw how to call and use _"built-in"_ functions.
Here, now, we are going to learn how to declare our owns. This will gives us
even more freedom to build our own logic.
### Declaring a very basic function
### Declaring a function
We mentioned before that a function had to be either assigned to a variable or
an object property.
@ -34,7 +32,7 @@ an object property.
We will now declare one in a variable. Let's call it: `myFirstFunction`.
Once a variable is declared; Remember how an array can be recognized with this
syntax : `[]`? or an object with this one : `{}` ?
syntax : `[]` ? or an object with this one : `{}` ?
Well, we will use another syntax for declaring our function. We will do so using
the `ArrowFunctionExpression` syntax : `() => {}`
@ -92,15 +90,10 @@ We actually used a function and gave it this single instruction:
### Instructions
You are a robot made by a scientist called Rick and you want to know your
purpose. We have declared the object `dialogue`. Declare **and call** a function
named `whatIsMyPurpose`.
- This function will display in the console the value of the key `myQuestion` in
the object `dialogue`.
Declare **and call** a function named `theAnswer`.
purpose.
- This function will display in the console the value of the key `Rick's answer`
in the object `dialogue`.
- Declare a function named `ask` that log `'What is my purpose ?'` in the
console
- Declare a function named `reply` that log `'You pass butter.'` in the console
Hint : Make sure your console is open if you want to see the actual answer :)
Then first call the `ask` then the `reply` once, in that order.

31
subjects/you-pass-butter/README.md

@ -1,8 +1,8 @@
## You pass butter
### Return value
### Return values
We are now going to see how to declare a function that returns an argument.
We are now going to see how to declare a function that returns a value.
Let's say we declare the variable `ten` the following way.
@ -11,11 +11,9 @@ let ten = 5 + 5
console.log(ten) // 10
```
We could replace those `5` with a very simple function that `returns` this
result. Let's call this function `returnsFive`. Let's not put any arguments in
this function to keep it very basic. The only new concept is the `return`
keyword. This keyword will return the specified value **and** end the function
execution.
We could replace those `5` with a function that `returns` this value. Let's call
this function `returnsFive`. The only new concept is the `return` keyword. It
returns the specified value **and** stop the function execution.
```js
let returnsFive = () => {
@ -33,16 +31,16 @@ console.log(ten) // 10
```
Now a question that you might ask yourself is: What if we had several `return`
keywords in the same function? Well as mentioned before, the `return` also stops
the function execution. So only the first `return` would matter. In fact that
means that anything after the `return` would not be executed. Example:
keywords in the same function ? Well as mentioned before, the `return` also
stops the function execution. So only the first `return` would matter. In fact
that means that anything after the `return` would not be executed. Example:
```js
let returnsFive = () => {
return 5 //ONLY this return is executed. Everything else is forgoten.
return 5 // ONLY this return is executed. Everything else is ignored.
return 10 // not executed (useless)
return 'I am useless' // not executed either
console.log('I am also useless') //nor this one
console.log('I am also useless') // nor this one
}
let ten = returnsFive() + returnsFive()
console.log(ten) // 10
@ -50,12 +48,13 @@ console.log(ten) // 10
```
As you may see, we get exactly the same result as the previous example.
`returnsFive` only returns 5. :)
`returnsFive` only returns `5`. :)
### Instructions
As Rick's robot, you now know your purpose. (Remember? 'You pass butter.')
As Rick's robot, you now know your purpose. (Remember ? `'You pass butter.'`)
Define the function `passButter` that returns `The butter`.
Define the function `passButter` that returns the string `'The butter'`.
![robot](https://media.discordapp.net/attachments/489466992286498816/828181031991377930/butter-disapointed.png?width=717&height=241)
![robot](https://media.discordapp.net/attachments/489466992286498816/828181031991377930/butter-disapointed.png
?width=717&height=241)

Loading…
Cancel
Save