---
# System prepended metadata

title: Function Exercises
tags: [Practice Assessment]

---

# Function Exercises

Functions are blocks of code that we can define as set to run at a later time in our code exectutions. They are an important part of programming and you will be hard pressed to find a real world application that does not use them. Functions are best used when you are trying to perform a specific task during executuion so its important to make the code with in its definition/scope relatable.  Below we will work through several functions in order to make sure we understand them.

----

### Dog Years

Given a that you have a pet dog for (x) amount of years create a function that will determine the actual age of the dog. We know that in dog years we will need to multiply the number of years you had it by 7 to get the dogs age. 

```
function dogYears(numOfYearsOwn){
    // ...code here
}

dogYears(2) // 14
```

----

### Build Array

Give that you have an array create a function that adds items to a specific index. This function should take in two argumnets an item to add and an index. This function should return the same array with the new value added. Each time you call the function it should add a new item and not get rid of the old one. 

```
let someArray = []

function buildArray(item, index){
   // ...code here
}

buildArray("oranges", 0)
buildArray("apples", 1)
buildArray("grapes", 2)

console.log(someArray) // ["oranges", "apples", "grapes"]
```

----

### Build Array 2

Given that you have an array create a function that adds items to a specific index. This function should take in two argumnets an item to add and an index. This function should return a ***different*** array with the new value added. Each time you call the function it should create a new item and not get rid of the old one. 

***Build of the previous excercise***

----

### Print Profile

Create a function that prints out a persons profile. This function should take in user data: first name, last name, age, hometown, email address as arguments respectfully. It should print the persons profile grouped in an object. Remember that objects use `key: value` pairing. 


```
function userProfile(firstName, lastName, email, hometown, age){
    //... code here
}

userProfile("Anakin", "Skywalker", "theone@test.com", "Tattoine", 32 ) // {name: Anakin Skywalker, email, "theone@test.com", hometown: "Tatooine", age: 32 }

```