diff --git a/js/tests/a-new-purpose.json b/js/tests/a-new-purpose.json new file mode 100644 index 00000000..9f366a4a --- /dev/null +++ b/js/tests/a-new-purpose.json @@ -0,0 +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, 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 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": "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": "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)" + } +] \ No newline at end of file diff --git a/js/tests/a-winning-argument.json b/js/tests/a-winning-argument.json new file mode 100644 index 00000000..3caf7366 --- /dev/null +++ b/js/tests/a-winning-argument.json @@ -0,0 +1,26 @@ +[ + { + "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": "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": "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}" + }, + { + "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}" + }, + { + "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}" + }, + { + "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}" + } +] \ No newline at end of file diff --git a/js/tests/give-it-a-rest.json b/js/tests/give-it-a-rest.json new file mode 100644 index 00000000..b44bba8e --- /dev/null +++ b/js/tests/give-it-a-rest.json @@ -0,0 +1,22 @@ +[ + { + "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": "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": "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": "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": "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)" + } +] \ No newline at end of file diff --git a/js/tests/happy.json b/js/tests/happy.json new file mode 100644 index 00000000..25904fd5 --- /dev/null +++ b/js/tests/happy.json @@ -0,0 +1,26 @@ +[ + { + "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}" + }, + { + "description": "happy has 1 argument", + "code": "if (happy.length != 1) {\n throw Error('You need 1 argument for this function!')\n}" + }, + { + "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": "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}" + }, + { + "description": "happy has no keyword return.", + "code": "if (happy.toString().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}" + } +] \ No newline at end of file diff --git a/js/tests/level-up.json b/js/tests/level-up.json new file mode 100644 index 00000000..68fecd64 --- /dev/null +++ b/js/tests/level-up.json @@ -0,0 +1,14 @@ +[ + { + "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 has 3 arguments", + "code": "if (shaker.length != 3) {\n throw Error('You need 3 arguments for this function!')\n}" + }, + { + "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')" + } +] \ No newline at end of file diff --git a/js/tests/my-house.json b/js/tests/my-house.json new file mode 100644 index 00000000..476f2e21 --- /dev/null +++ b/js/tests/my-house.json @@ -0,0 +1,22 @@ +[ + { + "description": "acidHouse and deepHouse are objects", + "code": "let mainHouse = { door: 'blue', rooms: { bedrooms: 2, bathrooms: 1 } }\n\n// Your code\n\nequal(typeof acidHouse, 'object')\nequal(typeof deepHouse, 'object')" + }, + { + "description": "acidHouse is not a reference", + "code": "let mainHouse = { door: 'blue', rooms: { bedrooms: 2, bathrooms: 1 } }\n\n// Your code\n\nmainHouse.door = 'red'\n\nif (acidHouse.door === 'red') {\n throw Error(\n 'when painting mainHouse.door in red, acidHouse.door is painted red too. You did not do a shallow copy',\n )\n}" + }, + { + "description": "acidHouse is not a deep copy", + "code": "let mainHouse = { door: 'blue', rooms: { bedrooms: 2, bathrooms: 1 } }\n\n// Your code\n\nmainHouse.rooms.bathrooms = 3\n\nif (acidHouse.rooms.bathrooms !== 3) {\n throw Error(\n 'when adding 2 bathrooms to mainHouse, acidHouse did not get 2 extra bathrooms as well, it looks like you did a deep copy instead of a shallow one...',\n )\n}" + }, + { + "description": "deepHouse is not a reference", + "code": "let mainHouse = { door: 'blue', rooms: { bedrooms: 2, bathrooms: 1 } }\n\n// Your code\n\nmainHouse.door = 'red'\n\nif (deepHouse.door === 'red') {\n throw Error(\n 'when painting mainHouse.door in red, deepHouse.door is painted red too, you did not do a deep copy',\n )\n}" + }, + { + "description": "deepHouse is not a shallow copy", + "code": "let mainHouse = { door: 'blue', rooms: { bedrooms: 2, bathrooms: 1 } }\n\n// Your code\n\nmainHouse.rooms.bathrooms = 3\n\nif (deepHouse.rooms.bathrooms !== 1) {\n throw Error(\n 'when adding 2 bathrooms to mainHouse, deepHouse didgot extra bathrooms as well, it looks like you did a shallow copy instead of a deep copy...',\n )\n}" + } +] \ No newline at end of file diff --git a/js/tests/parenting.json b/js/tests/parenting.json index 14550cfa..d565df4d 100644 --- a/js/tests/parenting.json +++ b/js/tests/parenting.json @@ -10,5 +10,9 @@ { "description": "child.parent must be equal to parent", "code": "equal(child.parent, parent)" + }, + { + "description": "child.parent.child must be equal to itself", + "code": "equal(child.parent.child, child)" } ] \ No newline at end of file diff --git a/js/tests/phant0m-writ3r.json b/js/tests/phant0m-writ3r.json new file mode 100644 index 00000000..c8277419 --- /dev/null +++ b/js/tests/phant0m-writ3r.json @@ -0,0 +1,22 @@ +[ + { + "description": "Tests with 'fermentation'", + "code": "let word = 'fermentation'\nconst args = saveArguments(console, 'log')\n\n// Your code\n\nequal(args[0], ['fermentation'])" + }, + { + "description": "Tests with 'bathrobe'", + "code": "let word = 'bathrobe'\nconst args = saveArguments(console, 'log')\n\n// Your code\n\nequal(args, [])" + }, + { + "description": "Tests with 'alimentation'", + "code": "let word = 'alimentation'\nconst args = saveArguments(console, 'log')\n\n// Your code\n\nequal(args, [])" + }, + { + "description": "Tests with 'alibaba'", + "code": "let word = 'alibaba'\nconst args = saveArguments(console, 'log')\n\n// Your code\n\nequal(args, [])" + }, + { + "description": "Tests with 'caution'", + "code": "let word = 'caution'\nconst args = saveArguments(console, 'log')\n\n// Your code\n\nequal(args[0], ['caution'])" + } +] \ No newline at end of file diff --git a/js/tests/rest-in-peace.json b/js/tests/rest-in-peace.json new file mode 100644 index 00000000..f15cd586 --- /dev/null +++ b/js/tests/rest-in-peace.json @@ -0,0 +1,46 @@ +[ + { + "description": "footSoldiers, horseMen, and armyOfTheDead are each an array", + "code": "let swordMen = []\nlet archers = []\nlet captains = []\nlet generals = []\n\n// Your code\n\nif (!Array.isArray(footSoldiers)) {\n throw Error('footSoldiers is not an Array')\n}\nif (!Array.isArray(horseMen)) {\n throw Error('horseMen is not an Array')\n}\nif (!Array.isArray(armyOfTheDead)) {\n throw Error('armyOfTheDead is not an Array')\n}" + }, + { + "description": "push is not used", + "code": "let swordMen = []\nlet archers = []\nlet captains = []\nlet generals = []\nconst pushCalls = saveArguments(Array.prototype, 'push')\n\n// Your code\n\nequal(pushCalls.length, 0) // push should not be used" + }, + { + "description": "unshift is not used", + "code": "let swordMen = []\nlet archers = []\nlet captains = []\nlet generals = []\nconst unshiftCalls = saveArguments(Array.prototype, 'unshift')\n\n// Your code\n\nequal(unshiftCalls.length, 0) // unshift should not be used" + }, + { + "description": "concat is not used", + "code": "let swordMen = []\nlet archers = []\nlet captains = []\nlet generals = []\nconst concatCalls = saveArguments(Array.prototype, 'concat')\n\n// Your code\n\nequal(concatCalls.length, 0) // concat should not be used" + }, + { + "description": "footSoldiers has 9 soldiers (including their leader)", + "code": "let swordMen = [\n 'Jack Churchill',\n 'Sasaki Kojiro',\n 'Johannes Liechtenauer',\n 'Fiore dei Liberi',\n]\nlet archers = ['William Tell', 'Artemis', 'Fred Bear', 'Nasu no Yoichi']\nlet captains = ['Guts', 'Edward the Black Prince', 'Joan of Arc']\nlet generals = ['Napoleon', 'Emilia Plater']\n\n// Your code\n\nequal(footSoldiers.length, 9)" + }, + { + "description": "Grim the Terrible is behind his footSoldiers", + "code": "let swordMen = [\n 'Jack Churchill',\n 'Sasaki Kojiro',\n 'Johannes Liechtenauer',\n 'Fiore dei Liberi',\n]\nlet archers = ['William Tell', 'Artemis', 'Fred Bear', 'Nasu no Yoichi']\nlet captains = ['Guts', 'Edward the Black Prince', 'Joan of Arc']\nlet generals = ['Napoleon', 'Emilia Plater']\n\n// Your code\n\nequal(footSoldiers, [\n 'Jack Churchill',\n 'Sasaki Kojiro',\n 'Johannes Liechtenauer',\n 'Fiore dei Liberi',\n 'William Tell',\n 'Artemis',\n 'Fred Bear',\n 'Nasu no Yoichi',\n 'Grim the Terrible',\n])" + }, + { + "description": "horseMen has 6 knights (including their leader)", + "code": "let swordMen = [\n 'Jack Churchill',\n 'Sasaki Kojiro',\n 'Johannes Liechtenauer',\n 'Fiore dei Liberi',\n]\nlet archers = ['William Tell', 'Artemis', 'Fred Bear', 'Nasu no Yoichi']\nlet captains = ['Guts', 'Edward the Black Prince', 'Joan of Arc']\nlet generals = ['Napoleon', 'Emilia Plater']\n\n// Your code\n\nequal(horseMen.length, 6)" + }, + { + "description": "The Skull Knight is in front of his horseMen", + "code": "let swordMen = [\n 'Jack Churchill',\n 'Sasaki Kojiro',\n 'Johannes Liechtenauer',\n 'Fiore dei Liberi',\n]\nlet archers = ['William Tell', 'Artemis', 'Fred Bear', 'Nasu no Yoichi']\nlet captains = ['Guts', 'Edward the Black Prince', 'Joan of Arc']\nlet generals = ['Napoleon', 'Emilia Plater']\n\n// Your code\n\nequal(horseMen, [\n 'The Skull Knight',\n 'Guts',\n 'Edward the Black Prince',\n 'Joan of Arc',\n 'Napoleon',\n 'Emilia Plater',\n])" + }, + { + "description": "armyOfTheDead is 16 soldiers strong", + "code": "let swordMen = [\n 'Jack Churchill',\n 'Sasaki Kojiro',\n 'Johannes Liechtenauer',\n 'Fiore dei Liberi',\n]\nlet archers = ['William Tell', 'Artemis', 'Fred Bear', 'Nasu no Yoichi']\nlet captains = ['Guts', 'Edward the Black Prince', 'Joan of Arc']\nlet generals = ['Napoleon', 'Emilia Plater']\n\n// Your code\n\nequal(armyOfTheDead.length, 16)" + }, + { + "description": "The King of the Dead is in between footSoldiers and horseMen", + "code": "let swordMen = [\n 'Jack Churchill',\n 'Sasaki Kojiro',\n 'Johannes Liechtenauer',\n 'Fiore dei Liberi',\n]\nlet archers = ['William Tell', 'Artemis', 'Fred Bear', 'Nasu no Yoichi']\nlet captains = ['Guts', 'Edward the Black Prince', 'Joan of Arc']\nlet generals = ['Napoleon', 'Emilia Plater']\n\n// Your code\n\nequal(armyOfTheDead, [\n 'Jack Churchill',\n 'Sasaki Kojiro',\n 'Johannes Liechtenauer',\n 'Fiore dei Liberi',\n 'William Tell',\n 'Artemis',\n 'Fred Bear',\n 'Nasu no Yoichi',\n 'Grim the Terrible',\n 'The King of the Dead',\n 'The Skull Knight',\n 'Guts',\n 'Edward the Black Prince',\n 'Joan of Arc',\n 'Napoleon',\n 'Emilia Plater',\n])" + }, + { + "description": "The army of the dead is still ordered if the soldiers are different", + "code": "let swordMen = [\n 'Zorro',\n 'Sasaki Kojiro',\n 'Johannes Liechtenauer',\n 'Fiore dei Liberi',\n]\nlet archers = [\n 'William Tell',\n 'Artemis',\n 'Fred Bear',\n 'Nasu no Yoichi',\n 'Rambo',\n]\nlet captains = ['Price', 'Guts', 'Edward the Black Prince', 'Joan of Arc']\nlet generals = ['Queen Elizabeth II', 'Emilia Plater']\n\n// Your code\n\nequal(armyOfTheDead, [\n 'Zorro',\n 'Sasaki Kojiro',\n 'Johannes Liechtenauer',\n 'Fiore dei Liberi',\n 'William Tell',\n 'Artemis',\n 'Fred Bear',\n 'Nasu no Yoichi',\n 'Rambo',\n 'Grim the Terrible',\n 'The King of the Dead',\n 'The Skull Knight',\n 'Price',\n 'Guts',\n 'Edward the Black Prince',\n 'Joan of Arc',\n 'Queen Elizabeth II',\n 'Emilia Plater',\n])" + } +] \ No newline at end of file diff --git a/js/tests/security.json b/js/tests/security.json new file mode 100644 index 00000000..28290857 --- /dev/null +++ b/js/tests/security.json @@ -0,0 +1,22 @@ +[ + { + "description": "Test a traveler that is still has the virus", + "code": "let traveler = {\n alreadyHadTheVirus: true,\n recovered: false,\n isVaccinated: false,\n}\n\n// Your code\n\nequal(traveler.isImmune, false)" + }, + { + "description": "Test a traveler that has recovered", + "code": "let traveler = {\n alreadyHadTheVirus: true,\n recovered: true,\n isVaccinated: false,\n}\n\n// Your code\n\nequal(traveler.isImmune, true)" + }, + { + "description": "Test a traveler who never had the virus and isn't vaccinated", + "code": "let traveler = {\n alreadyHadTheVirus: false,\n recovered: false,\n isVaccinated: false,\n}\n\n// Your code\n\nequal(traveler.isImmune, false)" + }, + { + "description": "Test a traveler that is vaccinated", + "code": "let traveler = {\n alreadyHadTheVirus: false,\n recovered: false,\n isVaccinated: true,\n}\n\n// Your code\n\nequal(traveler.isImmune, true)" + }, + { + "description": "Test a traveler that is vaccinated and recovered from the virus", + "code": "let traveler = { alreadyHadTheVirus: true, recovered: true, isVaccinated: true }\n\n// Your code\n\nequal(traveler.isImmune, true)" + } +] \ No newline at end of file diff --git a/js/tests/seeker-of-truth.json b/js/tests/seeker-of-truth.json new file mode 100644 index 00000000..8a0c4045 --- /dev/null +++ b/js/tests/seeker-of-truth.json @@ -0,0 +1,46 @@ +[ + { + "description": "Test with the falsy value 0", + "code": "const args = saveArguments(console, 'log')\nlet truth = 0\n\n// Your code\n\nequal(args[0]?.[0], 'Lies !!!!')" + }, + { + "description": "Test with the falsy value NaN", + "code": "const args = saveArguments(console, 'log')\nlet truth = NaN\n\n// Your code\n\nequal(args[0]?.[0], 'Lies !!!!')" + }, + { + "description": "Test with the falsy value undefined", + "code": "const args = saveArguments(console, 'log')\nlet truth = undefined\n\n// Your code\n\nequal(args[0]?.[0], 'Lies !!!!')" + }, + { + "description": "Test with the falsy value null", + "code": "const args = saveArguments(console, 'log')\nlet truth = null\n\n// Your code\n\nequal(args[0]?.[0], 'Lies !!!!')" + }, + { + "description": "Test with the falsy value ''", + "code": "const args = saveArguments(console, 'log')\nlet truth = ''\n\n// Your code\n\nequal(args[0]?.[0], 'Lies !!!!')" + }, + { + "description": "Test with the falsy value false", + "code": "const args = saveArguments(console, 'log')\nlet truth = false\n\n// Your code\n\nequal(args[0]?.[0], 'Lies !!!!')" + }, + { + "description": "Test with the truthy value 'Sure'", + "code": "const args = saveArguments(console, 'log')\nlet truth = 'Sure'\n\n// Your code\n\nequal(args[0]?.[0], 'The truth was spoken.')" + }, + { + "description": "Test with the truthy value []", + "code": "const args = saveArguments(console, 'log')\nlet truth = []\n\n// Your code\n\nequal(args[0]?.[0], 'The truth was spoken.')" + }, + { + "description": "Test with the truthy value {}", + "code": "const args = saveArguments(console, 'log')\nlet truth = {}\n\n// Your code\n\nequal(args[0]?.[0], 'The truth was spoken.')" + }, + { + "description": "Test with the truthy value true", + "code": "const args = saveArguments(console, 'log')\nlet truth = true\n\n// Your code\n\nequal(args[0]?.[0], 'The truth was spoken.')" + }, + { + "description": "Test with the truthy value -0.1", + "code": "const args = saveArguments(console, 'log')\nlet truth = -0.1\n\n// Your code\n\nequal(args[0]?.[0], 'The truth was spoken.')" + } +] \ No newline at end of file diff --git a/js/tests/special-promo.json b/js/tests/special-promo.json new file mode 100644 index 00000000..f0507c28 --- /dev/null +++ b/js/tests/special-promo.json @@ -0,0 +1,22 @@ +[ + { + "description": "Test with a user that can have the promotion", + "code": "const args = saveArguments(console, 'log')\nlet user = { activeMembership: true, age: 22 }\n\n// Your code\n\nequal(args[0]?.[0], 'You can benefit from our special promotion')" + }, + { + "description": "Test with a user that is too old", + "code": "const args = saveArguments(console, 'log')\nlet user = { activeMembership: true, age: 33 }\n\n// Your code\n\nequal(args[0]?.[0], undefined)" + }, + { + "description": "Test with a user that is too young", + "code": "const args = saveArguments(console, 'log')\nlet user = { activeMembership: true, age: 12 }\n\n// Your code\n\nequal(args[0]?.[0], undefined)" + }, + { + "description": "Test with a user that doesn't have an active membership", + "code": "const args = saveArguments(console, 'log')\nlet user = { activeMembership: false, age: 21 }\n\n// Your code\n\nequal(args[0]?.[0], undefined)" + }, + { + "description": "Test with a user that can have the promotion but is just at the limit", + "code": "const args = saveArguments(console, 'log')\nlet user = { activeMembership: true, age: 25 }\n\n// Your code\n\nequal(args[0]?.[0], 'You can benefit from our special promotion')" + } +] \ No newline at end of file diff --git a/js/tests/spread-the-word.json b/js/tests/spread-the-word.json new file mode 100644 index 00000000..d3ed7419 --- /dev/null +++ b/js/tests/spread-the-word.json @@ -0,0 +1,30 @@ +[ + { + "description": "beaconsLit is an Array", + "code": "const easternmost = 'Amon Dîn'\nlet easternBeacons = ['Eilenach', 'Nardol']\nconst centerBeacon = 'Erelas'\nlet westernBeacons = ['Min-Rimmon', 'Calenhad']\nconst westernmost = 'Amon Anwar'\n\n// Your code\n\nif (!Array.isArray(beaconsLit)) {\n throw Error('beaconsLit is not an Array')\n}" + }, + { + "description": "beaconsLit is created without using push", + "code": "const easternmost = 'Amon Dîn'\nlet easternBeacons = ['Eilenach', 'Nardol']\nconst centerBeacon = 'Erelas'\nlet westernBeacons = ['Min-Rimmon', 'Calenhad']\nconst westernmost = 'Amon Anwar'\nconst pushCalls = saveArguments(Array.prototype, 'push')\n\n// Your code\n\nequal(pushCalls.length, 0) // push should not be used" + }, + { + "description": "beaconsLit is created without using unshift", + "code": "const easternmost = 'Amon Dîn'\nlet easternBeacons = ['Eilenach', 'Nardol']\nconst centerBeacon = 'Erelas'\nlet westernBeacons = ['Min-Rimmon', 'Calenhad']\nconst westernmost = 'Amon Anwar'\nconst unshiftCalls = saveArguments(Array.prototype, 'unshift')\n\n// Your code\n\nequal(unshiftCalls.length, 0) // unshift should not be used" + }, + { + "description": "beaconsLit is created without using concat", + "code": "const easternmost = 'Amon Dîn'\nlet easternBeacons = ['Eilenach', 'Nardol']\nconst centerBeacon = 'Erelas'\nlet westernBeacons = ['Min-Rimmon', 'Calenhad']\nconst westernmost = 'Amon Anwar'\nconst concatCalls = saveArguments(Array.prototype, 'concat')\n\n// Your code\n\nequal(concatCalls.length, 0) // concat should not be used" + }, + { + "description": "beaconsLit has the 7 beacons lit", + "code": "const easternmost = 'Amon Dîn'\nlet easternBeacons = ['Eilenach', 'Nardol']\nconst centerBeacon = 'Erelas'\nlet westernBeacons = ['Min-Rimmon', 'Calenhad']\nconst westernmost = 'Amon Anwar'\n\n// Your code\n\nequal(beaconsLit.length, 7)" + }, + { + "description": "beaconsLit has the right beacons", + "code": "const easternmost = 'Amon Dîn'\nlet easternBeacons = ['Eilenach', 'Nardol']\nconst centerBeacon = 'Erelas'\nlet westernBeacons = ['Min-Rimmon', 'Calenhad']\nconst westernmost = 'Amon Anwar'\n\n// Your code\n\nequal(beaconsLit, [\n 'Amon Dîn',\n 'Eilenach',\n 'Nardol',\n 'Erelas',\n 'Min-Rimmon',\n 'Calenhad',\n 'Amon Anwar',\n])" + }, + { + "description": "beaconsLit should still work if the values are different", + "code": "const easternmost = 'Amon Din'\nlet easternBeacons = ['Eilenach']\nconst centerBeacon = 'नारडोल'\nlet westernBeacons = ['Erelas', 'Min-Rimmon', 'Calenhad']\nconst westernmost = 'Amon Anwar (Halifirien)'\n\n// Your code\n\nequal(beaconsLit, [\n 'Amon Din',\n 'Eilenach',\n 'नारडोल',\n 'Erelas',\n 'Min-Rimmon',\n 'Calenhad',\n 'Amon Anwar (Halifirien)',\n])" + } +] \ No newline at end of file diff --git a/js/tests/time-to-pay.json b/js/tests/time-to-pay.json new file mode 100644 index 00000000..bdf2d101 --- /dev/null +++ b/js/tests/time-to-pay.json @@ -0,0 +1,18 @@ +[ + { + "description": "Test with a customer that has enough cash", + "code": "let ticketSold = 8\nlet customer = { cash: 20, hasVoucher: false }\n\n// Your code\n\nequal(ticketSold, 9)" + }, + { + "description": "Test with a customer that has a voucher", + "code": "let ticketSold = 5\nlet customer = { cash: 0, hasVoucher: true }\n\n// Your code\n\nequal(ticketSold, 6)" + }, + { + "description": "Test with a customer that has a voucher and cash", + "code": "let ticketSold = 6\nlet customer = { cash: 42, hasVoucher: true }\n\n// Your code\n\nequal(ticketSold, 7)" + }, + { + "description": "Test with a customer that can not afford the ticket", + "code": "let ticketSold = 3\nlet customer = { cash: 3, hasVoucher: false }\n\n// Your code\n\nequal(ticketSold, 3)" + } +] \ No newline at end of file diff --git a/js/tests/to-infinity-and-beyond.json b/js/tests/to-infinity-and-beyond.json new file mode 100644 index 00000000..590eadac --- /dev/null +++ b/js/tests/to-infinity-and-beyond.json @@ -0,0 +1,6 @@ +[ + { + "description": "Not implemented", + "code": "throw Error('oops')" + } +] \ No newline at end of file diff --git a/js/tests/two-can-play-that-game.json b/js/tests/two-can-play-that-game.json new file mode 100644 index 00000000..177d5a8e --- /dev/null +++ b/js/tests/two-can-play-that-game.json @@ -0,0 +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 has two arguments", + "code": "if (duos.length != 2) {\n throw Error('You need two arguments for this function!')\n}" + }, + { + "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": "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 has three arguments", + "code": "if (duosWork.length != 3) {\n throw Error('You need three arguments for this function!')\n}" + }, + { + "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}" + } +] \ No newline at end of file diff --git a/js/tests/virus19.json b/js/tests/virus19.json new file mode 100644 index 00000000..c9be1159 --- /dev/null +++ b/js/tests/virus19.json @@ -0,0 +1,18 @@ +[ + { + "description": "Freeze the virus19", + "code": "const antivirus = { C8H10N4O: true, C12H22O11: true }\nconst virus19 = {\n dangerosity: 'extremely dangerous',\n contagiousness: 'contagious',\n}\n\n// Your code\n\nif (!Object.isFrozen(virus19)) {\n throw Error('you did not freeze the virus19 properly. It can mutate!')\n}" + }, + { + "description": "vaccine is an object", + "code": "const antivirus = { C8H10N4O: true, C12H22O11: true }\nconst virus19 = {\n dangerosity: 'extremely dangerous',\n contagiousness: 'contagious',\n}\n\n// Your code\n\nequal(typeof vaccine, 'object')" + }, + { + "description": "vaccine contains the right molecules", + "code": "const antivirus = { C8H10N4O: true, C12H22O11: true }\nconst virus19 = {\n dangerosity: 'extremely dangerous',\n contagiousness: 'contagious',\n}\n\n// Your code\n\nequal(vaccine, antivirus)" + }, + { + "description": "vaccine is frozen", + "code": "const antivirus = { C8H10N4O: true, C12H22O11: true }\nconst virus19 = {\n dangerosity: 'extremely dangerous',\n contagiousness: 'contagious',\n}\n\n// Your code\n\nif (!Object.isFrozen(vaccine)) {\n throw Error('you did not secure your vaccine components')\n}" + } +] \ No newline at end of file diff --git a/js/tests/what-else.json b/js/tests/what-else.json new file mode 100644 index 00000000..80010fa6 --- /dev/null +++ b/js/tests/what-else.json @@ -0,0 +1,18 @@ +[ + { + "description": "Test with an empty list", + "code": "let vips = []\nconst args = saveArguments(console, 'log')\n\n// Your code\n\nequal(args[0], ['The only failure is not to try.'])" + }, + { + "description": "Test if he is not invited", + "code": "let vips = ['Dora', 'Bruce Willis']\nconst args = saveArguments(console, 'log')\n\n// Your code\n\nequal(args[0], ['The only failure is not to try.'])" + }, + { + "description": "Test if he is in the list", + "code": "let vips = ['Dora', 'Jacky', 'George Clooney', 'Bruce Willis']\nconst args = saveArguments(console, 'log')\n\n// Your code\n\nequal(args[0], ['What else ?'])" + }, + { + "description": "Test if he is the first in the list", + "code": "let vips = ['George Clooney', 'Jacky', 'Bruce Willis']\nconst args = saveArguments(console, 'log')\n\n// Your code\n\nequal(args[0], ['What else ?'])" + } +] \ No newline at end of file diff --git a/js/tests/what-is-my-purpose.json b/js/tests/what-is-my-purpose.json new file mode 100644 index 00000000..fc2c76cb --- /dev/null +++ b/js/tests/what-is-my-purpose.json @@ -0,0 +1,26 @@ +[ + { + "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": "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": "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": "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": "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}" + } +] \ No newline at end of file diff --git a/js/tests/you-pass-butter.json b/js/tests/you-pass-butter.json new file mode 100644 index 00000000..8fbccb0b --- /dev/null +++ b/js/tests/you-pass-butter.json @@ -0,0 +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 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": "// Your code\n\nlet theTable = passButter()\n\nif (theTable != 'The butter') {\n throw Error(`passButter() did not return 'The butter'`)\n}" + } +] \ No newline at end of file diff --git a/subjects/a-new-purpose/README.md b/subjects/a-new-purpose/README.md new file mode 100644 index 00000000..049d1fd3 --- /dev/null +++ b/subjects/a-new-purpose/README.md @@ -0,0 +1,53 @@ +## A new purpose + +### Treating data in and out + +You know now how to declare the `arguments` and the `return` values of a +function. You know have the tools to: + +- receive data in the function (in the form of the arguments) +- treat the data (in the fonction scope) +- return the treated data (with the return keyword) + +You can now for example, transform this function which we used right before: + +```js +let myFirstFunction = (continent, country, city, temperature) => { + console.log(continent, country, city, temperature) +} //<- end of the scope of the function +// Now we call the function +myFirstFunction('Europe', 'France', 'Paris', '30°C') +// 'Europe' +// 'France' +// 'Paris' +// '30°C' +``` + +into: + +```js +let myFirstFunction = (continent, country, city, temperature) => { + // { + //<-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() +} //<-end of the scope of the function +``` + +Now the function if called, display the output the `console.log(arg1)`. + +```js +myFirstFunction('using my first arg') // "using my first arg" +``` + +But let's say we want to change what the function logs. Now, instead of +modifying `myFirstFunction` we just need to modify the argument in the function +call. + +```js +myFirstFunction('another arg') // "another arg" +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. +> +> - Marcus Aurelius + +### Instructions + +You are a general's aide who has to transmit the communications to the other +soldiers. + +In order to do so you will create the function `battleCry`. This function will +take one argument and will display it in the console. + +The battlefield is big so make sure that the argument is uppercased before +displaying it. + +Now, sometimes the communications will have to given quietly. + +For this you will create the function `secretOrders` which does the same as +`battleCry` except that it lowercases the argument before sending it. diff --git a/subjects/access/README.md b/subjects/access/README.md index 4594545d..1dd7fc24 100644 --- a/subjects/access/README.md +++ b/subjects/access/README.md @@ -1,4 +1,4 @@ -## Access +## Access 🔑 Now that we know how to define objects, let's start to use them diff --git a/subjects/all-caps/README.md b/subjects/all-caps/README.md index 8bb106c6..36ef3b9d 100644 --- a/subjects/all-caps/README.md +++ b/subjects/all-caps/README.md @@ -19,9 +19,9 @@ 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. +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. @@ -30,8 +30,8 @@ Since they are functions, they can also return values. 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`. +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. diff --git a/subjects/alter-ego/README.md b/subjects/alter-ego/README.md index bc4125e5..a6265451 100644 --- a/subjects/alter-ego/README.md +++ b/subjects/alter-ego/README.md @@ -1,4 +1,4 @@ -## Alter Ego +## Alter Ego 🎭 You can change your objects in multiple ways: diff --git a/subjects/anything-to-declare/README.md b/subjects/anything-to-declare/README.md index 697ae2fd..809ad23b 100644 --- a/subjects/anything-to-declare/README.md +++ b/subjects/anything-to-declare/README.md @@ -1,4 +1,4 @@ -## Anything to Declare ? +## Anything to Declare ? 🛂 ### Variables diff --git a/subjects/cut/README.md b/subjects/cut/README.md index 9b676cc6..467b8024 100644 --- a/subjects/cut/README.md +++ b/subjects/cut/README.md @@ -1,9 +1,9 @@ -## Cut +## Cut ✂️ ### Instructions -Using the `.slice` method and the provided `alphabet` variable which is a string of all -the character in an alphabet: +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`. diff --git a/subjects/give-it-a-rest/README.md b/subjects/give-it-a-rest/README.md new file mode 100644 index 00000000..0b425af4 --- /dev/null +++ b/subjects/give-it-a-rest/README.md @@ -0,0 +1,23 @@ +## 🌟 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: + +```js +console.log(addAll(1)) //1 +console.log(addAll(1, 10)) //11 +console.log(addAll(1, 10, 100)) //111 +``` + +You will then do exactly the same for `subAll`, `MultAll` and `divAll`. diff --git a/subjects/griswold-the-blacksmith/README.md b/subjects/griswold-the-blacksmith/README.md index 36697018..76e24dce 100644 --- a/subjects/griswold-the-blacksmith/README.md +++ b/subjects/griswold-the-blacksmith/README.md @@ -1,4 +1,4 @@ -## Griswold the Blacksmith +## Griswold the Blacksmith ⚒️ Methods and built-in functions are good, but most of the time we have to write our own logic and the first block for that are **conditions**. @@ -35,8 +35,8 @@ There are 6 different comparaison opperators: - `!==` _not equal to_ Every comparaison operator are _like_ functions, they take 2 arguments, one on -the right and one on the left, and returns a boolean value. Either `true`, if the -condition is met, or `false` if it's not. +the right and one on the left, and returns a boolean value. Either `true`, if +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: @@ -60,7 +60,8 @@ Scopes are a way to group lines of code, this allow us to do multiple lines of code if a condition is true. ```js -if (age > 48) { // <-beginning of the scope of the if condition +if (age > 48) { + // <-beginning of the scope of the if condition console.log('You are over 48 years old') } // <- end of the scope of the if condition ``` @@ -69,8 +70,8 @@ if (age > 48) { // <-beginning of the scope of the if condition Upon writing code inside a scope, it's an important convention to **indent** it. -Indenting is when spaces are added at the beginning of the line, here is an example of -bad code: +Indenting is when spaces are added at the beginning of the line, here is an +example of bad code: ```js @@ -96,8 +97,8 @@ the code clear. ### Instructions -You are Griswold the Blacksmith, and you must give the list of items the -player can buy with the money he has, here is what you are selling: +You are Griswold the Blacksmith, and you must give the list of items the player +can buy with the money he has, here is what you are selling: - arrows for 3 coins - boots for 44 coins @@ -106,8 +107,7 @@ player can buy with the money he has, here is what you are selling: Declare a `purchasableGoods` array and _conditionally_ push to it all the goods that the player can buy. -Use `if` conditions and compare the cost of the goods with the provided -variable `playerCoins` that contains the number of coins available to -the player. +Use `if` conditions and compare the cost of the goods with the provided variable +`playerCoins` that contains the number of coins available to the player. > You must order elements by price diff --git a/subjects/happy/README.md b/subjects/happy/README.md new file mode 100644 index 00000000..cf4b689c --- /dev/null +++ b/subjects/happy/README.md @@ -0,0 +1,31 @@ +## 🌟 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) + +### Instructions + +With all the 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 +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. + +Examples: + +```js +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 +``` + +Any other requests will be denied with a `false`. (if it is not a question of if +it does not have the word `happy`). + +And because you aim for efficiency you will contruct your fonction without the +curlys brackets `{}` and without the keyword `return` or `if`. diff --git a/subjects/keep/README.md b/subjects/keep/README.md index f5778d66..4209505f 100644 --- a/subjects/keep/README.md +++ b/subjects/keep/README.md @@ -2,8 +2,8 @@ ### Instructions -Using the `.slice` method again and the provided `alphabet` variable of a string of -all the characters in an alphabet: +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`. diff --git a/subjects/level-up/README.md b/subjects/level-up/README.md new file mode 100644 index 00000000..3fc236b2 --- /dev/null +++ b/subjects/level-up/README.md @@ -0,0 +1,52 @@ +## level up + +You know now, in your function declarations, how to use arguments and returns. + +Let's try to now use the `if` statements in a new function called `happy`. Here +is an example: + +```js +let happy = (mood) => { + if (mood === 'happy') { + return true + } + return false +} + +let result1 = happy('happy') +let result2 = happy('sad') + +console.log(result1) //true +console.log(result2) //false +``` + +Here we used the `if` statement, and two `return` keywords to alternate between +the result `true` or `false` depending whether the argument `mood` is equal to +the string `happy` or not. The possibilities are becoming limitless... + +### Instructions + +As Rick's robot, you are continuing your training to add yourself new ... skills +(I could have said funtions). You want now to become a robot bartender. + +Define the function `shaker` which will take as arguments: + +- `quantity`, which will be variable of type `Number` +- `fruit`, which will be a `String` +- `alcohol`, which will be a `Boolean` + +`shaker` must return a `String`. Look at the examples below to understand how +`shaker` must mix its ingredients: + +```js +console.log(shaker(1, 'strawberry', true)) +//'1 strawberry cocktail' +console.log(shaker(2, 'chocolate', false)) +//'2 chocolate milkshakes' +console.log(shaker(2, 'strawberry', true)) +//'2 strawberry cocktails' +console.log(shaker(1, 'chocolate', false)) +//'1 chocolate milkshake' +``` + +Ps: watch out for your plurals! diff --git a/subjects/maximus/README.md b/subjects/maximus/README.md index fb0f5bc2..e07fc541 100644 --- a/subjects/maximus/README.md +++ b/subjects/maximus/README.md @@ -1,4 +1,4 @@ -## Maximus +## Maximus ⚔️ ![maximus](https://user-images.githubusercontent.com/231748/112197288-d322dd00-8c03-11eb-95e4-a5253043578d.jpg) @@ -17,7 +17,8 @@ Values are simply separated by a `,` comma, like values in an Array. 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. +- Declare an `oldestAge` variable that use the `Math.max` on their `age` + property to find the oldest age. + +Hint: Maybe find out how the Math.max function works before starting this +exercise. diff --git a/subjects/my-house/README.md b/subjects/my-house/README.md new file mode 100644 index 00000000..590e5152 --- /dev/null +++ b/subjects/my-house/README.md @@ -0,0 +1,64 @@ +## 🌟 My House 🏠 + +One should be aware that copying an objet in Js is not a straightfoward process. +Let's try with an object `mainHouse`. Given what we know, the first instinct +would be to do something like this: + +```js +let mainHouse = { + door: 'blue', + rooms: { + bedrooms: 2, + bathrooms: 1, + }, +} + +let sameHouse = mainHouse +``` + +If we `console.log` both `mainHouse` and `sameHouse` we will obtain exactly the +same output: + +```js +console.log(mainHouse) // { door: 'blue', rooms: 3 } +console.log(sameHouse) // { door: 'blue', rooms: 3 } +``` + +So far, so good. Now, let's get into the issue. Let's paint the door of +`mainHouse` in `red`. + +```js +mainHouse.door = 'red' +``` + +If we `console.log` both `mainHouse` and `sameHouse` we will now obtain: + +```js +console.log(mainHouse) // { door: 'red', rooms: 3} +console.log(sameHouse) // { door: 'red', rooms: 3} +``` + +But wait a second... we just wanted to paint the door of `mainHouse`. What +happened here? Why are both doors painted in red? + +Well, unlike primitives that can not changes, _(the number `1` will always be +the number `1`)_ objects can mutate. + +You can add, delete and update properties, so if two different variables are +assigned to the same object value, they will both mutate the same object. + +We call that a reference, not a copy. + +There are multiple ways to copies objects. Understanding the limitations of each +of these ways is very important. Which is why this time, you will have to do a +bit of research... + +### Instructions + +We will declare the same `mainHouse` seen in the lesson above. + +- Declare `acidHouse` which will be a `shallow copy` of `mainHouse`. +- Declare `deepHouse` which will be a `deep copy` of `mainHouse`. + +> Not in my house! \ +> ― Dikembe Mutombo diff --git a/subjects/notorious/README.md b/subjects/notorious/README.md index 08a43494..bce699a6 100644 --- a/subjects/notorious/README.md +++ b/subjects/notorious/README.md @@ -1,4 +1,4 @@ -## 🌟 Notorious +## 🌟 Notorious 🎤 ### Notions diff --git a/subjects/parenting/README.md b/subjects/parenting/README.md index 284fd7b7..a9aad971 100644 --- a/subjects/parenting/README.md +++ b/subjects/parenting/README.md @@ -1,4 +1,4 @@ -## 🌟 Parenting +## 🌟 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 diff --git a/subjects/phant0m-writ3r/README.md b/subjects/phant0m-writ3r/README.md new file mode 100644 index 00000000..0962c1f1 --- /dev/null +++ b/subjects/phant0m-writ3r/README.md @@ -0,0 +1,27 @@ +## PHANT0M-WRiT3R 👻 + +### Using functions in conditions + +Any expressions is valid code inside conditions, that includes functions calls: + +```js +// for example, we can uppercase to make sure it will match +// no mater if the name has upper or lower letter ! +if ('Patrick Lemaire'.toUpperCase() === 'PATRICK LEMAIRE') { + console.log('This is Patrick') +} +``` + +### Instructions + +Your carreer as a rap ghost writer is at a dead end as inspiration seems to have +left for good, but you still have an ace up your sleeve, you will write a bot +`PHANT0M-WRiT3R` that find ryhmes for you ! + +- Log the provided variable `word` if it does not start with `'al'` and end with + `'ion'` + +### Notions + +- [startsWith](https://devdocs.io/javascript/global_objects/string/startsWith) +- [endsWith](https://devdocs.io/javascript/global_objects/string/endsWith) diff --git a/subjects/pop-art/README.md b/subjects/pop-art/README.md index 8b830838..e57b4610 100644 --- a/subjects/pop-art/README.md +++ b/subjects/pop-art/README.md @@ -1,4 +1,4 @@ -## Pop Art +## Pop Art 🎨 ### Instructions diff --git a/subjects/ratchet-clap/README.md b/subjects/ratchet-clap/README.md index cad617ea..2edb429b 100644 --- a/subjects/ratchet-clap/README.md +++ b/subjects/ratchet-clap/README.md @@ -1,4 +1,4 @@ -## Ratchet Clap +## Ratchet👏Clap👏 Let's do the opposite ! diff --git a/subjects/redeclaration-of-love/README.md b/subjects/redeclaration-of-love/README.md index cc1a70b3..d1aaa4b6 100644 --- a/subjects/redeclaration-of-love/README.md +++ b/subjects/redeclaration-of-love/README.md @@ -1,4 +1,4 @@ -## Redeclaration of Love +## Redeclaration of Love 💕 ### Assign, re-assign diff --git a/subjects/rest-in-peace/README.md b/subjects/rest-in-peace/README.md new file mode 100644 index 00000000..2e7093ba --- /dev/null +++ b/subjects/rest-in-peace/README.md @@ -0,0 +1,42 @@ +## 🌟 Rest in peace + +### Notions + +- [devdocs.io/operators/spread_syntax](https://devdocs.io/javascript/operators/spread_syntax) + +### Instructions + +The battle is won! The Army of the Dead have finally fulfilled their oath. It is +now time to free them so that they may rest in peace. + +But first we need to regroup and count them to make sure not one single soul is +left behind. We will provide a four variables of type array: + +- `swordMen` +- `archers` +- `captains` +- `generals` + +You will need to concat the content of `swordMen` and `archers` into one array +`footSoldiers`. That batallion is lead by `'Grim the Terrible'`. He likes to +scream to soldiers that walks too slow, so you need to put him as the last +element of the array. + +Then you will do the same for `captains` and `generals` into the array +`horseMen`. That batallion is lead by `'The Skull Knight'`. He, on the other +hand, likes to lead from the front. He needs to be the first element of the +array. + +Finally you will do it one more time for `footSoldiers` and `horseMen` into the +array `armyOfTheDead`. For having a better overview, `'The King of the Dead'` +needs to be tactically positioned in between his foot soldiers and his knights. + +Oh! and here is a little detail, the methods `concat`, `push` and `unshift` were +damaged during the battle... so find another way. + +Hurry, they are waiting... + +> Well, this is a thing unheard of. \ +> An Elf would go underground, where a Dwarf dare not. \ +> Oh, I'd never hear the end of it.! \ +> ― Gimli diff --git a/subjects/security/README.md b/subjects/security/README.md new file mode 100644 index 00000000..f3b88edf --- /dev/null +++ b/subjects/security/README.md @@ -0,0 +1,17 @@ +## Security + +### AND + OR (`&&` + `||`) + +Combining `&&` and `||` builds complex logical conditions. + +You can use `()` to group them. + +### Instructions + +The infamous **virus19** is spreading ! As an airport control agent your role is +to ensure that the traveler is safe for his flight. + +You must define the `traveler.isImmune` property to `true` if either: + +- both `traveler.alreadyHadTheVirus` and `traveler.recovered` are `true` +- or `traveler.isVaccinated` is `true` diff --git a/subjects/seeker-of-truth/README.md b/subjects/seeker-of-truth/README.md index 684a1186..8e9be254 100644 --- a/subjects/seeker-of-truth/README.md +++ b/subjects/seeker-of-truth/README.md @@ -2,15 +2,19 @@ ### 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. +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. +All other values are truthy, note that empty arrays and empty objects are +truthy, but the empty string is not. ```js if ('') { @@ -24,7 +28,8 @@ if ('hello') { ### Operator `!` -The `!` (NOT operator) can be used to convert a truthy value to `false` or a falsy value to `true`. +The `!` (NOT operator) can be used to convert a truthy value to `false` or a +falsy value to `true`. example: @@ -35,16 +40,12 @@ let noMoney = !money console.log(noMoney) // true ``` -In this case, 0 is falsy, so the `!` return the value `true` +In this case, 0 is falsy, so the `!` return the value `true` ### Instructions -R - -```js -let truth = 0 +Seek the truth and claim your verdict ! -if (!truth) { - console.log() -} -``` +- Log `'The truth was spoken.'` if the value of the provided variable `truth` is + truthy +- Log `'Lies !!!!'` if the value of the provided variable `truth` is falsy diff --git a/subjects/special-promo/README.md b/subjects/special-promo/README.md new file mode 100644 index 00000000..b2d83b4b --- /dev/null +++ b/subjects/special-promo/README.md @@ -0,0 +1,27 @@ +## Special Promo 🎟️ + +### `&&` (the AND operator) + +This operator is used to group conditions: + +```js +if (user.role === 'admin' && user.available === 'now') { + console.log('Admin', user.name, 'is available and will help you now !') +} +``` + +Here, the code will only show the message if **both** conditions are true. + +### Instructions + +Your traveling company have a new special promo for members between 18 and 25 +years old. + +Write the `if` condition that will check if the user can benefit the promotion: + +- `user.age` must be at least `18` +- `user.age` must be lesser or equal to `25` +- `user.activeMembership` must be `true` + +If all of those conditions are true, `console.log` the message +`You can benefit from our special promotion` diff --git a/subjects/spread-the-word/README.md b/subjects/spread-the-word/README.md new file mode 100644 index 00000000..c82aa5cc --- /dev/null +++ b/subjects/spread-the-word/README.md @@ -0,0 +1,19 @@ +## 🌟 Spread the Word 💬 + +### Notions + +- [devdocs.io/operators/spread_syntax](https://devdocs.io/javascript/operators/spread_syntax) + +### Instructions + +Gondor needs help! + +To call for help you will have to concat the provided strings and arrays; +`easternmost` (string), `easternBeacons` (array), `centerBeacon` (string), +`westernBeacons` (array) and `westernmost` (string) into the variable array +`beaconsLit` that you will declare. Only one array of burning fires must be left +at the end. + +Unfortunately young hobbit, the guards are watching the `Array.concat()`, the +`Array.unshift()` and the `Array.push()` methods. You will have to find another +way... diff --git a/subjects/the-true-king/README.md b/subjects/the-true-king/README.md index 0d518a05..5e920522 100644 --- a/subjects/the-true-king/README.md +++ b/subjects/the-true-king/README.md @@ -1,4 +1,4 @@ -## The True King +## The True King 👑 ### Instructions diff --git a/subjects/time-to-pay/README.md b/subjects/time-to-pay/README.md new file mode 100644 index 00000000..574db505 --- /dev/null +++ b/subjects/time-to-pay/README.md @@ -0,0 +1,26 @@ +## Time to Pay 💸 + +### `||` (the OR operator) + +The other way to group condtions: + +```js +if (user.role === 'admin' || user.role === 'moderator') { + console.log(user.name, 'has access to moderation pages.') +} +``` + +Here, the code will only show the message if **any** conditions are true. + +### Instructions + +You are selling planes tickets, they all cost `9.99$` you must confirm that the +`customer` has the means to buy this ticket. The `customer` may have enough +`cash` or a `voucher` + +Check if the provided variable `customer` can afford the ticket: + +- whether he has enough cash (`customer.cash` property) +- or, if he has a voucher (`customer.hasVoucher` property is `true`) + +If so, you must increment the provided variable `ticketSold` value by `1`. diff --git a/subjects/to-infinity-and-beyond/README.md b/subjects/to-infinity-and-beyond/README.md new file mode 100644 index 00000000..65e12635 --- /dev/null +++ b/subjects/to-infinity-and-beyond/README.md @@ -0,0 +1,43 @@ +## To Infinity And Beyond + +### The `else if` keyword + +Last keyword of the serie, this one combine the two previous keywords to allow +to chain conditions: + +```js +if (temperature < 8) { + console.log('very cold !') +} else if (temperature < 16) { + console.log('still too cold...') +} else if (temperature < 24) { + console.log('getting warmer') +} else if (temperature < 32) { + console.log('nice :)') +} else { + console.log('Too hot !!!') +} +``` + +You can chain as mainy as you want, the syntax is similar to the if. + +### Instructions + +The year is 2042 Elon's dream came true He now has spaceship lines to mars and +to the moon and a big pool of candidates who all want to go to space but there +is still a heavy selection process based on: + +- number `candidate.physicalAptitudes` from `0` to `100` +- boolean `candidate.noFamily` + +You have to create a condition to go to Mars which is always the most demanded +destination for this destination: + +- if the candidate `physicalAptitudes` are below `80`, he must stay on `'earth'` +- only candidates with `noFamily` can go on `'mars'` +- otherwhise they can still go to the `'moon'` + +You must log which planet the `candidate` can access + +> And there seems to be no sign of intelligent life anywhere. \ +> ― Buzz Lightyear diff --git a/subjects/two-can-play-that-game/README.md b/subjects/two-can-play-that-game/README.md new file mode 100644 index 00000000..e754d724 --- /dev/null +++ b/subjects/two-can-play-that-game/README.md @@ -0,0 +1,81 @@ +## Two can play that game + +### Arguments (Continued) + +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`. + +```js +let myFirstFunction = (arg1, arg2) => { + //<-arg1 and arg2 are inputed in between the parens + console.log(arg1, arg2) + // ↖ arg1 and arg2 are "transfered" to be the args of console.log() +} +// Now we call the function +myFirstFunction('first arg', 'second arg') +// "first arg" +// "second arg" +``` + +For more args, you will need to simply repeat the same process. Example with +`arg3` and `arg4`: + +```js +let myFirstFunction = (arg1, arg2, arg3, arg4) => { + // { + // Our Business Is Life Itself \ +> ― Umbrella Corporation's slogan diff --git a/subjects/what-else/README.md b/subjects/what-else/README.md index 002bd258..d15cbb28 100644 --- a/subjects/what-else/README.md +++ b/subjects/what-else/README.md @@ -1,3 +1,27 @@ ## What else ? - if / else + includes? +### The `else` keyword + +It allows to execute alternative code if the condition do not match: + +```js +if (isEnough) { + console.log('this is enough :)') +} else { + console.log('I want more !!') +} +``` + +it is like an `if` but you don't have a condition, just add a scope after `{}` +and write code ! + +### Instructions + +You must check if `'George Clooney'` is included in the provided array `vips` + +if he is, `console.log` the string `'What else ?'` otherwhise log +`'The only failure is not to try.'` + +### Notions + +- [includes](https://devdocs.io/javascript/global_objects/array/includes) diff --git a/subjects/what-is-my-purpose/README.md b/subjects/what-is-my-purpose/README.md new file mode 100644 index 00000000..96078890 --- /dev/null +++ b/subjects/what-is-my-purpose/README.md @@ -0,0 +1,106 @@ +## 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?: + +```js +// ↙ identifier, like variables +console.log('Hello There !') // <- function call happening here +// ↖ open paren + argument + close paren +``` + +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. + +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 + +We mentioned before that a function had to be either assigned to a variable or +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 : `{}` ? + +Well, we will use another syntax for declaring our function. We will do so using +the `ArrowFunctionExpression` syntax : `() => {}` + +- So we first put parens `()`, These, are the containers of the `arguments` that + go in the function. For now we will leave them empty with no arguments. (More + on those later on) +- We then add the arrow `=>` which is the distinguishing feature of the + `ArrowFunctionExpression` syntax. +- Finally, we add the curly brackets `{}` to delimite the scope of our newly + created function. Note: They are not always necessary, you will probably find + examples of this function syntax without the `{}`. However, for now because + you are learning. We will put them most of the time. + +```js +// ↙ normal variable ↙ beginning of the scope of the function +let myFirstFunction = () => { + // ↖ parens () for arguments and the arrow => for syntax +} // <-end of the scope of the function +``` + +It's now possible to call this function using the `()`, like any pre-declared +function: + +```js +myFirstFunction() // nothing happens +``` + +This function if called, does not do anything, since it doesn't contain any +code. + +### The scope of a function `{}` + +Very much like an `if` statement a function has a scope. The scope in between +the curly braces`{}` is where the action happens. Let's add something to the +scope of our function. + +```js +let myFirstFunction = () => { + console.log('Calling my first function') + // ↖ some instructions to do when the function is called ! +} +``` + +Now the function if called, display the output the `console.log()`. + +```js +myFirstFunction() // "Calling my first function" +``` + +We actually used a function and gave it this single instruction: + +- call another function `console.log()`. + +### 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`. + +- This function will display in the console the value of the key `Rick's answer` + in the object `dialogue`. + +Hint : Make sure your console is open if you want to see the actual answer :) diff --git a/subjects/wololo/README.md b/subjects/wololo/README.md index f45b3fe5..1aa854d2 100644 --- a/subjects/wololo/README.md +++ b/subjects/wololo/README.md @@ -1,4 +1,4 @@ -## 🌟 Wololo +## 🌟 Wololo 🧙 ### Converting types @@ -43,9 +43,15 @@ type. Using the magical power of functions, execute the following conversions: -- Declare a `stringFromNumber` variable of the converted value of `num` to a `string` -- Declare a `stringFromBoolean` variable of the converted value of `bool` to a `string` -- Declare a `numberFromString` variable of the converted value of `str` to a `number` -- Declare a `numberFromBoolean` variable of the converted value of `bool` to a `number` -- Declare a `booleanFromString` variable of the converted value of `str` to a `boolean` -- Declare a `booleanFromNumber` variable of the converted value of `num` to a `boolean` +- Declare a `stringFromNumber` variable of the converted value of `num` to a + `string` +- Declare a `stringFromBoolean` variable of the converted value of `bool` to a + `string` +- Declare a `numberFromString` variable of the converted value of `str` to a + `number` +- Declare a `numberFromBoolean` variable of the converted value of `bool` to a + `number` +- Declare a `booleanFromString` variable of the converted value of `str` to a + `boolean` +- Declare a `booleanFromNumber` variable of the converted value of `num` to a + `boolean` diff --git a/subjects/words/README.md b/subjects/words/README.md index af29c6b5..64bed903 100644 --- a/subjects/words/README.md +++ b/subjects/words/README.md @@ -2,10 +2,11 @@ ### Instructions -**Split** the provided variable `sentence` using spaces as separator to create an array of words. -You will assign the result to a `words` variable that you will declare. +**Split** the provided variable `sentence` using spaces as separator to create +an array of words. You will assign the result to a `words` variable that you +will declare. -Hint: Check the link below to see what the method split does and how to use it. +Hint: Check the link below to see what the method split does and how to use it. ### Notions diff --git a/subjects/you-pass-butter/README.md b/subjects/you-pass-butter/README.md new file mode 100644 index 00000000..42964603 --- /dev/null +++ b/subjects/you-pass-butter/README.md @@ -0,0 +1,61 @@ +## You pass butter + +### Return value + +We are now going to see how to declare a function that returns an argument. + +Let's say we declare the variable `ten` the following way. + +```js +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. + +```js +let returnsFive = () => { + return 5 + // ↖ the keyword `return`, returns the value right after it, + // in this case the number 5. +} +``` + +Now that the function is declared, we call it where we need it. + +```js +let ten = returnsFive() + returnsFive() +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: + +```js +let returnsFive = () => { + return 5 //ONLY this return is executed. Everything else is forgoten. + return 10 // not executed (useless) + return 'I am useless' // not executed either + console.log('I am also useless') //nor this one +} +let ten = returnsFive() + returnsFive() +console.log(ten) // 10 +//exactly the same result as the previous example +``` + +As you may see, we get exactly the same result as the previous example. +`returnsFive` only returns 5. :) + +### Instructions + +As Rick's robot, you now know your purpose. (Remember? 'You pass butter.') + +Define the function `passButter` that returns `The butter`. + +![robot](https://media.discordapp.net/attachments/489466992286498816/828181031991377930/butter-disapointed.png?width=717&height=241) diff --git a/subjects/you-spin-me-round/README.md b/subjects/you-spin-me-round/README.md index b140475c..a944e162 100644 --- a/subjects/you-spin-me-round/README.md +++ b/subjects/you-spin-me-round/README.md @@ -5,7 +5,7 @@ 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. +That seems pretty complicated but it is the building 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 `()`. @@ -21,9 +21,10 @@ console.log('Hello There !') #### 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 +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 @@ -88,16 +89,16 @@ 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. +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. +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