Skip to content

Joshua Cheney #134

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -12,20 +12,20 @@ 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 `<firstName-lastName>`.
- [ ] Implement the project on your newly created `<firstName-lastName>` branch, committing changes regularly
- [ ] Push commits: git push origin `<firstName-lastName>`
- [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 `<firstName-lastName>`.
- [X] Implement the project on your newly created `<firstName-lastName>` branch, committing changes regularly
- [X] Push commits: git push origin `<firstName-lastName>`

### Task 2 - MVP

Find the file `index.js` and complete the tasks until your returns look like the expected returns. Do not use any of the forbidden methods!

### 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

Expand Down
211 changes: 80 additions & 131 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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 '[email protected]' as arguments,
* the returned value should look like:
Expand All @@ -96,58 +103,71 @@ function temperatureInF(/* code here */) {
* email: "[email protected]",
* }
*/
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","[email protected]"))

/**
* ### 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: '[email protected]` } 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 : "[email protected]",
};
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 ].
Expand Down Expand Up @@ -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.
**/
Expand All @@ -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`.
*/
Expand All @@ -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`.
*/
Expand All @@ -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.
Expand All @@ -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 */
}