diff --git a/README.md b/README.md index 4cfee49c0..ba27cf66f 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ This challenge focuses on functions, objects and arrays. You'll convert "traditional" functions into functions that use the ES6 arrow syntax. You'll also manipulate objects and traverse arrays. -__THE USE OF _MOST_ HIGHER-ORDER ARRAY METHODS IS FORBIDDEN!__ These would be array methods that take callbacks as arguments and save you from having to loop manually, such as `map`, `filter`, `reduce`,`forEach` etc. **You'll have to make do with good old loops!** +__THE USE OF _MOST_ HIGHER-ORDER ARRAY METHODS IS FORBIDDEN!__ These would be array methods that take callbacks as arguments and save you from having to loop manually, such as `map`, `filter`, `reduce`,`forEach` etc. **You'll have to make do with good old loops!** Commit often! **Plan to commit & push every time you get a new test passing**. This makes it SO much easier to figure out "what broke my code", and helps your TL keep track of how you're doing. @@ -12,12 +12,12 @@ If you run into trouble while coding, fight the good fight for 20 minutes and th ### Task 1 - Set up Project -- [ ] Create a forked copy of this project -- [ ] Add your team lead as collaborator on Github -- [ ] Clone your OWN version of the repository (Not Lambda's by mistake!) -- [ ] Create a new branch: git checkout -b ``. -- [ ] Implement the project on your newly created `` branch, committing changes regularly -- [ ] Push commits: git push origin `` +- [X] Create a forked copy of this project +- [X] Add your team lead as collaborator on Github +- [X] Clone your OWN version of the repository (Not Lambda's by mistake!) +- [X] Create a new branch: git checkout -b ``. +- [X] Implement the project on your newly created `` branch, committing changes regularly +- [X] Push commits: git push origin `` ### Task 2 - MVP @@ -25,7 +25,7 @@ Find the file `index.js` and complete the tasks until your returns look like the ### Task 3 - Stretch -There are several stretch goals inside `index.js`. You may work on these once you have finished MVP requirements for the day! +There are several stretch goals inside `index.js`. You may work on these once you have finished MVP requirements for the day! ## Resources diff --git a/index.js b/index.js index 3a474a3f4..df76afc6e 100644 --- a/index.js +++ b/index.js @@ -2,11 +2,11 @@ /** * ### Challenge `addNumbers` - * + * * @instructions * This function should be able to take two numbers as arguments * and return the result of adding them together. - * + * * For example, if we invoke `addNumbers` passing 5 and 3, * the returned value should be 8. * @@ -26,67 +26,74 @@ function addNumbers(num1, num2) { /** * ### Challenge `sayGoodbye` - * - * @instructions + * + * instructions * This function should take an a name as an argument, * and return a string that says 'Goodbye, {name}. Have a great day.' - * + * * For example, if we invoke `sayGoodbye` * passing 'Andy' as the argument, * the returned value should look like: 'Goodbye, Andy. Have a great day.' - * + * */ -function sayGoodbye(/* code here */) { - /* code here */ +function sayGoodbye(name) { + return `Goodbye, ${name}. Have a great day.`; } +console.log(sayGoodbye("Joshua")); /** * ### Challenge `temperatureCtoF` - * - * @instructions + * + * instructions * This function should take an a temperature in celsius as an argument, - * and return the temperature in fahrenheit, rounded to the nearest whole number. - * + * and return the temperature in fahrenheit, rounded to the nearest whole number. + * * For example, if we invoke `temperatureCtoF` * passing 24 as the argument, * the returned value should be: 75 - * + * * Hint 1: The formula for converting celsius to fahrenheit is t*9/5 + 32 where t is the temperature in celsius. - * Hint 2: There is a very easy way to round numbers in JS. Do a google search to find out how. + * Hint 2: There is a very easy way to round numbers in JS. Do a google search to find out how. */ -function temperatureCtoF(/* code here */) { - /* code here */ +function temperatureCtoF(temp) { + return Math.round(temp * (9 / 5) + 32); } +console.log(temperatureCtoF(24)); /** * ### Challenge `temperatureInF` - * - * @instructions + * + * instructions * This function should take an a temperature and a unit (either 'F' or 'C') as arguments, - * and return the temperature in fahrenheit, rounded to the nearest whole number. - * + * and return the temperature in fahrenheit, rounded to the nearest whole number. + * * For example, if we invoke `temperatureInF` * passing 88, 'F' as the arguments, * the returned value should be: '88F' - * + * * If we invoke `temperatureInF` * passing 24, 'C' as the arguments, * the returned value should be: '75F' - * + * * Hint: You can call your `temperatureCtoF` function from inside `temperatureInF`. */ -function temperatureInF(/* code here */) { - /* code here */ +function temperatureInF(temp,unit) { + if (unit === "F"){ + return (temp + unit); + } + else if (unit === "C"){ + return temperatureCtoF(temp) + "F"; + } } - +console.log(temperatureInF(24,"C")) /** * ### Challenge `makePersonObject` - * - * @instructions + * + * instructions * This function should take an id, a name and an email as arguments, * and return an object with `id`, `name` and `email` properties. - * + * * For example, if we invoke `makePersonObject` * passing 5, 'Leia' and 'leia@leia.com' as arguments, * the returned value should look like: @@ -96,58 +103,71 @@ function temperatureInF(/* code here */) { * email: "leia@leia.com", * } */ -function makePersonObject(/* code here */) { - /* code here */ +function makePersonObject(id,name,email) { + const person = { + id : id, + name : name, + email : email, + }; + return person; } +console.log(makePersonObject(5,"Leia","leia@leia.com")) /** * ### Challenge `getName` - * - * @instructions + * + * instructions * This function takes as its only argument * an object containing a `name` property, * and return a string that reads `Hello, my name is {name}`, * where `{name}` is the name stored in the object. - * + * * For example, if we invoke `getName` * passing { id: 1, name: 'Leia', email: 'leia@leia.com` } as the argument, * the returned value should look like `Hello, my name is Leia`. */ function getName(/* code here */) { - /* code here */ + return (`Hello, my name is ${personal.name}`) } - + const personal = { + id : 5, + name : "Leia", + email : "leia@leia.com", + }; +console.log(getName(personal)) /** * ### Challenge `appleIndex` - * - * @instructions - * This function takes as its only argument an array + * + * instructions + * This function takes as its only argument an array * containing strings, * and returns the index in the array of the string 'apple'. - * - * You may assume the string 'apple' will appear exactly + * + * You may assume the string 'apple' will appear exactly * once in the array. - * + * * For example, if we invoke `appleIndex` * passing in [ 'orange', 'grape', 'apple', 'banana', 'mango' ] as the argument, * the returned value should be: 2. */ -function appleIndex(/* code here */) { - /* code here */ +function appleIndex(fruitArray) { + var fruitOfChoice = fruitArray.indexOf("apple"); + return fruitOfChoice; } +console.log(appleIndex(['orange', 'grape', 'apple', 'banana', 'mango'])) /** * ### Challenge `isItAnApple` - * - * @instructions - * This function takes as its only argument an array + * + * instructions + * This function takes as its only argument an array * containing strings, * and returns an array of equal length containing the `true` - * if the corresponding entry in the original array is 'apple' + * if the corresponding entry in the original array is 'apple' * and `false` if it is anything else. - * - * + * + * * For example, if we invoke `isItAnApple` * passing in [ 'orange', 'apple', 'banana', 'apples', 'apple', 'mango' ] as the argument, * the returned value should be: [ false, true, false, false, true, false ]. @@ -180,10 +200,10 @@ var inventory = [ /** * ### Example Array Challenge: - * - * @instructions + * + * instructions * get3rdCar() should return the string `The is a Land Rover Defender Ice Edition` - * + * * * NOTE: This example has been completed for you. **/ @@ -199,13 +219,13 @@ function get3rdCar(inventory) { /** * ### Challenge `getCarInfoByIndex` - * - * @instructions + * + * instructions * getCarInfoByIndex takes two arguments: * (1) an array which is an inventory of cars like the preview above (see ⭐️ Preview Test Data ⭐️) * (2) a number which is the desired index in the array. * getCarInfoByIndex returns a string in the format `This is a {car_make} {car_model}` - * + * * For example, if getCarInfoByIndex is invoked with the inventory and the number 0, * it will return `This is a Lincoln Navigator`. */ @@ -215,12 +235,12 @@ function getCarInfoByIndex(inventory, index) { /** * ### Challenge `getLastCarInfo` - * - * @instructions + * + * instructions * getLastCarInfo takes a single argument: * (1) an array which is an inventory of cars like the one inside /data/inventory.js. * getLastCarInfo returns a string in the format `This is a {car_make} {car_model} - * + * * For example, if getLastCarInfo is invoked passing the inventory inside /data/inventory.js, * it will return `This is a Lincoln Town Car`. */ @@ -230,8 +250,8 @@ function getLastCarInfo(/* code here */) { /** * ### Challenge `getModelYears` - * - * @instructions + * + * instructions * We need the years from every car in the inventory! * getModelYears takes a single argument: * (1) an array which is an inventory of cars like the one inside /data/inventory.js. @@ -240,74 +260,3 @@ function getLastCarInfo(/* code here */) { function getModelYears(/* code here */) { /* code here */ } - -/** - * ### Challenge `getCarInfoById` - * * * THIS ONE IS A STRETCH GOAL. ATTEMPT IT ONLY AFTER - * COMPLETING ALL NON-STRETCH CHALLENGES IN THE REPOSITORY! - * - * @instructions - * getCarInfoById takes two arguments: - * (1) an array which is an inventory of cars like the one inside /data/inventory.js. - * (2) a number which is the desired car id (see how each car has its own unique id). - * getCarInfoById returns a string in the format `This is a {car_make} {car_model} - * - * For example, if getCarInfoById is invoked with the inventory and the number 1, - * it will return `This is a Lincoln Navigator`. -*/ -function getCarInfoById(/* code here */) { - /* code here */ -} - -/** - * ### Challenge `getOlderCars` - * * THIS ONE IS A STRETCH GOAL. ATTEMPT IT ONLY AFTER - * COMPLETING ALL NON-STRETCH CHALLENGES IN THE REPOSITORY! - * - * @instructions - * We need a utility to find older cars! - * getOlderCars takes two arguments: - * (1) an array which is an inventory of cars like the one inside /data/inventory.js. - * (2) a number which is the desired max year. - * getOlderCars returns an array containing all the cars - * with a `car_year` which is at most the given desired max year, - * in the same order as they appear in the original inventory. -*/ -function getOlderCars(/* code here */) { - /* code here */ -} - -/** - * ### Challenge `getGermanCars` - * * THIS ONE IS A STRETCH GOAL. ATTEMPT IT ONLY AFTER - * COMPLETING ALL NON-STRETCH CHALLENGES IN THE REPOSITORY! - * - * @instructions - * We need a utility to find German cars! - * getGermanCars takes a single argument: - * (1) an array which is an inventory of cars like the one inside /data/inventory.js. - * getGermanCars returns an array containing all the cars - * made by either `Audi` or `Mercedes-Benz` or `Volkswagen` or `BMW`, - * in the same order as they appear in the original inventory. -*/ -function getGermanCars(/* code here */) { - /* code here */ -} - -/** - * ### Challenge `carMaker` - * THIS ONE IS A STRETCH GOAL. ATTEMPT IT ONLY AFTER - * COMPLETING ALL NON-STRETCH CHALLENGES IN THE REPOSITORY! - * - * @instructions - * This function takes a single odometer argument (a number) and returns an object. - * The returned object has the following characteristics: - * it has an `odometer` property that contains the argument passed in. - * it has a `drive` method that takes a distance as its argument, and - * (1) causes the odometer in the object to be increased by the distance, - * (2) returns the updated value of the `odometer`. -*/ -function carMaker(/* code here */) { - /* code here */ -} -