diff --git a/index.js b/index.js index aca98f3..0ff3640 100644 --- a/index.js +++ b/index.js @@ -3,11 +3,12 @@ function spotEachRebel(rebels) { /** * @BUG ALERT - We need to be pushing 'Look! Rebel scum!' once for each rebel spotted - * The number of rebels can be expected to exactly equal the number of times that 'Look! Rebel scum!' is included + * Fixed, added a forEach loop to add in a phrase for each rebel */ - if (rebels) { + // eslint-disable-next-line no-unused-vars + rebels.forEach(() => { spottedRebelCalls.push('Look! Rebel scum!') - } + }) return spottedRebelCalls } @@ -19,7 +20,8 @@ function shootAtNothing() { let shotsAtNothing = [] /** @BUG ALERT - Looping is not quite correct */ - for (let i = 1; i < 4; i++) { + /** Fixed, set i =0 instead of 1 so that it counts 4 times not 3 */ + for (let i = 0; i < 4; i++) { shotsAtNothing.push('pew') } diff --git a/loops-object-es6.js b/loops-object-es6.js index 59a3ab5..4c76a32 100644 --- a/loops-object-es6.js +++ b/loops-object-es6.js @@ -1,7 +1,40 @@ +/* eslint-disable no-console */ +/* eslint-disable no-unused-vars */ // review of loops +// array data type has forEach() +// for loop +// while loop +for (let i = 0; i <= 10; i++) { + // eslint-disable-next-line no-console + console.log('Loop number ' + i) +} // introducing arrow functions +function calculateAge() {} +const calculateHeight = () => {} + +const officeWorkers = ['Toby', 'Creed', 'Kevin', 'Michael'] + +officeWorkers.forEach((officeWorker) => { + console.log(officeWorker) +}) // more about objects +const cloneTrooper = { + name: 'Fin', + rank: 'Lead' +} + +cloneTrooper.rank = 'E1' + // triple dot `...` aka destructuring +const [firstPerson, secondPerson, ...everyOneElse] = officeWorkers + +console.log({ firstPerson, secondPerson, everyOneElse }) + +// ... Object +const nameThisWay = cloneTrooper.name +const { name } = cloneTrooper + +console.log({ nameThisWay, name }) diff --git a/package.json b/package.json index e60948d..c51848c 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,8 @@ "main": "index.js", "scripts": { "lint": "eslint --format codeframe .", - "test": "mocha -w" + "test": "mocha -w", + "play": "node loops-object-es6.js" }, "author": "", "license": "ISC",