From 3e76d799e58cc6c915bf2a00d7b6928e0f35c833 Mon Sep 17 00:00:00 2001 From: caglenoah Date: Wed, 19 Jul 2023 16:20:39 -0600 Subject: [PATCH 1/6] challenges complete, come back and do the bonus --- main.js | 109 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) diff --git a/main.js b/main.js index e69de29..3dcd456 100644 --- a/main.js +++ b/main.js @@ -0,0 +1,109 @@ +//CHALENGES---------------------------------- + + +/** `.length`---- + * Create an array called `cars` which consists of 4 different types of cars as String type. The first car type should be Ford. + * Console.log the length of the array. + * Use`node main.js` to run the program. + */ + +// create array we will call cars. cars = array +const cars = ['Ford', 'Toyota', 'Jeep', 'Subaru']; +console.log(cars.length) + + +//---- + + +/** `.concat()`------ + * Create another array called `moreCars` with 4 more different types of cars. The last car type should be Honda. + * Use the `concat()` method to combine the `cars` and `moreCars` arrays into another array called `totalCars`. + * Console.log the new array. + * Run the program. + */ + +//create an array called more cars. more cars = array +const moreCars = ['Chrystler', 'Chevy', 'Tesla', 'Honda']; +//total cars = cars + moreCars +const totalCars = cars.concat(moreCars); +console.log(totalCars) + + +//---- + + +// `.indexOf()` and `.lastIndexOf()`---- +// * Use the `indexOf` method to console.log the index of `Honda` in `totalCars`. +// * Use the `lastIndexOf` method to console.log the index of `Ford` in `totalCars`. +// * Run the program. + +//get the index of honda from total cars +console.log(totalCars.indexOf('Honda')); +//returns 7 + +//get the index of ford fro totalCars +console.log(totalCars.lastIndexOf('Ford')); +// returns 0 +//---- + +// `.join()`---- +// * Use the `join` method to convert the array `totalCars` into a string called `stringOfCars`. +// * Console.log `stringOfCars`. +// * Run the program. + +//convert an array into a string +const stringOfCars = totalCars.join(); +console.log(stringOfCars) +//---- + + + +// `.split()`---- +// * Use the `split` method to convert `stringOfCars` into an array called `carsFromString`. +// * Console.log the array you just created. +// * Run the program. + +//turn a string into an array +const carsFromString = stringOfCars.split(); +console.log(carsFromString) + + + + + +//NOTESFORREPL!!!!------------------------------- +//Concat()---- + +// const array1 = ['a', 'b', 'c']; +// const array2 = ['d', 'e', 'f']; +// const array3 = array1.concat(array2); +// console.log(array3); +//---- + +//indexOf()---- +// const beasts = ['ant', 'bison', 'camel', 'duck', 'bison']; +// console.log(beasts.indexOf('bison')); +// // Expected output: 1 +// // Start from index 2 +// console.log(beasts.indexOf('bison', 2)); +// // Expected output: 4 +// console.log(beasts.indexOf('giraffe')); +// // Expected output: -1 +// //----- + +// //const animals = ['Dodo', 'Tiger', 'Penguin', 'Dodo']; +// console.log(animals.lastIndexOf('Dodo')); +// // Expected output: 3 +// console.log(animals.lastIndexOf('Tiger')); +// // Expected output: 1 +// ---- + +// const elements = ['Fire', 'Air', 'Water']; +// console.log(elements.join()); +// // Expected output: "Fire,Air,Water" +// console.log(elements.join('')); +// // Expected output: "FireAirWater" +// console.log(elements.join('-')); +// // Expected output: "Fire-Air-Water" +// ---- + From ea8c3ee6c9283f3d1e88c3274fbf968833d4c0b3 Mon Sep 17 00:00:00 2001 From: caglenoah Date: Wed, 19 Jul 2023 16:25:23 -0600 Subject: [PATCH 2/6] must have made a little change --- README.md | 4 ++++ main.js | 3 +++ 2 files changed, 7 insertions(+) diff --git a/README.md b/README.md index f4512ec..6dff6a8 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,10 @@ * Use the `split` method to convert `stringOfCars` into an array called `carsFromString`. * Console.log the array you just created. * Run the program. + + + + > BONUS: Go back and pass a comma (`','`) in as an argument to `.split()` to separate the cars into individual items in the array. This is called a *separator* and it can be any character you wish to separate strings by. 1. `.reverse()` * Use the `reverse` method to create an array `carsInReverse` which is the array `totalCars` in reverse. diff --git a/main.js b/main.js index 3dcd456..79d4b9e 100644 --- a/main.js +++ b/main.js @@ -66,6 +66,9 @@ console.log(stringOfCars) //turn a string into an array const carsFromString = stringOfCars.split(); console.log(carsFromString) +//---- + + From b9a1c38c9b9b755b12766ae3b772eb23ba923c21 Mon Sep 17 00:00:00 2001 From: caglenoah Date: Thu, 20 Jul 2023 02:47:36 -0600 Subject: [PATCH 3/6] solved more challenges, deleted redundancies in my notes. Added a place to list all the fnction i used here to reference. --- README.md | 137 +++++++++++++++++++++++++++--------------------------- main.js | 114 +++++++++++++++++++++++++++++++-------------- 2 files changed, 147 insertions(+), 104 deletions(-) diff --git a/README.md b/README.md index 6dff6a8..a99fd77 100644 --- a/README.md +++ b/README.md @@ -11,76 +11,75 @@ 1. Fork and Clone 1. Create a new branch called: `yourName-ArrayChallenge` 1. Install dependecies: `npm i` (see `package.json`) -3. Use a whiteboard to work out a solution to the challenges below -4. Translate the broad ideas to pseudo code -5. Convert the pseudo code to real JavaScript code -6. Type into your text editor the JavaScript code you've come up with one step at a time -7. Work through your bugs. -8. Use `node main.js` to run the program after **every** line of code you build. +1. Use a whiteboard to work out a solution to the challenges below +1. Translate the broad ideas to pseudo code +1. Convert the pseudo code to real JavaScript code +1. Type into your text editor the JavaScript code you've come up with one step at a time +1. Work through your bugs. +1. Use `node main.js` to run the program after **every** line of code you build. ### Challenges 1. `.length` - * Create an array called `cars` which consists of 4 different types of cars as String type. The first car type should be Ford. - * Console.log the length of the array. - * Use `node main.js` to run the program. + - Create an array called `cars` which consists of 4 different types of cars as String type. The first car type should be Ford. + - Console.log the length of the array. + - Use `node main.js` to run the program. 1. `.concat()` - * Create another array called `moreCars` with 4 more different types of cars. The last car type should be Honda. - * Use the `concat` method to combine the `cars` and `moreCars` arrays into another array called `totalCars`. - * Console.log the new array. - * Run the program. + - Create another array called `moreCars` with 4 more different types of cars. The last car type should be Honda. + - Use the `concat` method to combine the `cars` and `moreCars` arrays into another array called `totalCars`. + - Console.log the new array. + - Run the program. 1. `.indexOf()` and `.lastIndexOf()` - * Use the `indexOf` method to console.log the index of `Honda` in `totalCars`. - * Use the `lastIndexOf` method to console.log the index of `Ford` in `totalCars`. - * Run the program. + - Use the `indexOf` method to console.log the index of `Honda` in `totalCars`. + - Use the `lastIndexOf` method to console.log the index of `Ford` in `totalCars`. + - Run the program. 1. `.join()` - * Use the `join` method to convert the array `totalCars` into a string called `stringOfCars`. - * Console.log `stringOfCars`. - * Run the program. + - Use the `join` method to convert the array `totalCars` into a string called `stringOfCars`. + - Console.log `stringOfCars`. + - Run the program. 1. `.split()` - * Use the `split` method to convert `stringOfCars` into an array called `carsFromString`. - * Console.log the array you just created. - * Run the program. - - - - - > BONUS: Go back and pass a comma (`','`) in as an argument to `.split()` to separate the cars into individual items in the array. This is called a *separator* and it can be any character you wish to separate strings by. + - Use the `split` method to convert `stringOfCars` into an array called `carsFromString`. + - Console.log the array you just created. + - Run the program. + BONUS: Go back and pass a comma (`','`) in as an argument to `.split()` to separate the cars into individual items in the array. This + is called a _separator_ and it can be any character you wish to separate strings by. 1. `.reverse()` - * Use the `reverse` method to create an array `carsInReverse` which is the array `totalCars` in reverse. - * Console.log `carsInReverse`. - * Run the program. + - Use the `reverse` method to create an array `carsInReverse` which is the array `totalCars` in reverse. + - Console.log `carsInReverse`. + - Run the program. 1. `.sort()` - * Use the `sort` method to put the array `carsInReverse` into alphabetical order. - * Based on the types of cars you used, predict which item in the array should be at index 0. - * Use the following code to confirm or reject your prediction: `console.log(carsInReverse.indexOf('yourPrediction'));` + - Use the `sort` method to put the array `carsInReverse` into alphabetical order. + - Based on the types of cars you used, predict which item in the array should be at index 0. + - Use the following code to confirm or reject your prediction: `console.log(carsInReverse.indexOf('yourPrediction'));` + Create a `pets` array by copy/pasting the following: `const pets = ['dog', 'cat', 'fish', 'rabbit', 'snake', 'lizard', 'bird']` 1. `.slice()` - * Create a `pets` array by copy/pasting the following: `const pets = ['dog', 'cat', 'fish', 'rabbit', 'snake', 'lizard', 'bird']` - * Use the `slice` method to create a `reptiles` array with `snake` and `lizard` from the `pets` array. - * Console.log the `reptiles` array and run the program. - * Now console.log the `pets` array and run the program. Why do you think `snake` and `lizard` are still in the original array? + - Use the `slice` method to create a `reptiles` array with `snake` and `lizard` from the `pets` array. + - Console.log the `reptiles` array and run the program. + - Now console.log the `pets` array and run the program. Why do you think `snake` and `lizard` are still in the original array? 1. `.splice()` - * Create a new array called `removedReptiles`, using the `splice` method to remove `snake` and `lizard` from the `pets` array. - * Console.log `removedReptiles` and `pets` and run the program. - * Go back and add the string `'hamster'` in as a third parameter to your `splice` method, then run the program again and notice how the `pets` array has changed. Do you see how that works? + - Create a new array called `removedReptiles`, using the `splice` method to remove `snake` and `lizard` from the `pets` array. + - Console.log `removedReptiles` and `pets` and run the program. + +- Go back and add the string `'hamster'` in as a third parameter to your `splice` method, then run the program again and notice how the `pets` array has changed. Do you see how that works? + 1. `.pop()` - * Use the `pop` method to remove the last item from the `pets` array, saving it to a variable called `removedPet`. - * Console.log `removedPet` and `pets` and run the program. + - Use the `pop` method to remove the last item from the `pets` array, saving it to a variable called `removedPet`. + - Console.log `removedPet` and `pets` and run the program. 1. `.push()` - * Use the `push` method to add `removedPet` back to the end of the `pets` array. - * Console.log `pets` and run the program. + - Use the `push` method to add `removedPet` back to the end of the `pets` array. + - Console.log `pets` and run the program. 1. `.shift()` - * Use the `shift` method to remove and console.log the first item in the `pets` array. + - Use the `shift` method to remove and console.log the first item in the `pets` array. 1. `.unshift()` - * Use the `unshift` method to add the string `'turtle'` as the first item in the `pets` array. - * Console.log the `pets` array and run the program. If all went according to plan, you should see `['turtle', 'cat', 'fish', 'rabbit', 'hamster', 'bird']`. + - Use the `unshift` method to add the string `'turtle'` as the first item in the `pets` array. + - Console.log the `pets` array and run the program. If all went according to plan, you should see `['turtle', 'cat', 'fish', 'rabbit', 'hamster', 'bird']`. 1. `.forEach()` - * Create a numbers array by copy/pasting the following: `const numbers = [23, 45, 0 , 2, 8, 44, 100, 1, 3, 91, 34]` - * Write code that will add 2 to each item in the array `numbers`. - * `forEach` requires a function to be passed into it as its first argument. - * Build a function called `addTwo` that can take in num, index, and arr as parameters—`(num, index, arr)`—and returns `num + 2` at each `index` of the `arr`. - * Use `.forEach()` on the `numbers` array, passing in your freshly built function `addTwo` as an argument, in order to add 2 to each number in the array. - * Console.log `numbers` and run the program. + - Create a numbers array by copy/pasting the following: `const numbers = [23, 45, 0 , 2, 8, 44, 100, 1, 3, 91, 34]` + - Write code that will add 2 to each item in the array `numbers`. + - `forEach` requires a function to be passed into it as its first argument. + - Build a function called `addTwo` that can take in num, index, and arr as parameters—`(num, index, arr)`—and returns `num + 2` at each `index` of the `arr`. + - Use `.forEach()` on the `numbers` array, passing in your freshly built function `addTwo` as an argument, in order to add 2 to each number in the array. + - Console.log `numbers` and run the program. ### Hints @@ -89,7 +88,7 @@ 1. Push yourself to learn on your own. Ask: How does this work? 1. **Clone, setup, testing, and running instructions for all projects is below** -****** +--- ## Cloning Your Project @@ -97,15 +96,15 @@ 1. Copy HTTPS URL from your forked repository 1. In your terminal/gitBash/CommandPrompt navigate (using `cd`) into a directory where you want to start keeping your repositories. (`/jsDevFolder`) 1. Clone your new repository by typing `git clone ` (the HTTPS -URL you copied above) - ![Forking a repository](https://docs.google.com/drawings/d/1tYsLHaLo8JRdp0xC1EZrAo0o9Wvv4S5AD937cokVOBk/pub?w=960&h=720) + URL you copied above) + ![Forking a repository](https://docs.google.com/drawings/d/1tYsLHaLo8JRdp0xC1EZrAo0o9Wvv4S5AD937cokVOBk/pub?w=960&h=720) 1. Now go into the new directory by using `cd project-repo` 1. Add the base repository as an upstream - `git remote add upstream https://github.com/AustinCodingAcademy/.git` + `git remote add upstream https://github.com/AustinCodingAcademy/.git` 1. Check the configuration of your remotes with `git remote -v`, it should look -very similar to this (except it'll be YOUR username) + very similar to this (except it'll be YOUR username) ```bash $ git remote -v @@ -119,32 +118,32 @@ upstream git@github.com:AustinCodingAcademy/javascript-workbook.git (push) ### Setup 1. From your project directory, run `npm i` to tell NPM to install all the -node modules we use in this class (see `package.json`) + node modules we use in this class (see `package.json`) 1. Use your textEditor (VS Code) to change your files. 1. When you're finished `git status`, stage your file `git add .`, commit your changes `git commit -m "functions working"`, and push to -GitHub `git push` - ```bash + GitHub `git push` + `bash git status git add . git commit -m "Initial Commit" git push origin gh-pages - ``` + ` 1. Now go to your forked repository on GitHub (at - https://github.com/your-username/javascript-workbook). A little yellow box - should have popped up asking you to make a Pull Request. Click to review. + https://github.com/your-username/javascript-workbook). A little yellow box + should have popped up asking you to make a Pull Request. Click to review. 1. Click "Create Pull Request" -1. Every time you make a change *and push to GitHub*, this PR will automatically -update. No need to do it more than once. +1. Every time you make a change _and push to GitHub_, this PR will automatically + update. No need to do it more than once. #### Get latest workbook updates 1. To get the latest code/homework/test updates, be sure to have a "clean -working directory" by committing or removing all of your changes. You check for -a "clean working environment" by running `git status` and making sure no files -show up. + working directory" by committing or removing all of your changes. You check for + a "clean working environment" by running `git status` and making sure no files + show up. 1. Run `git pull upstream gh-pages` diff --git a/main.js b/main.js index 79d4b9e..7b6739b 100644 --- a/main.js +++ b/main.js @@ -63,50 +63,94 @@ console.log(stringOfCars) // * Console.log the array you just created. // * Run the program. -//turn a string into an array -const carsFromString = stringOfCars.split(); +//turn a string into an array !!!!this is a SERATOR!!!! Instead of returning the string as one element in an array, dependant on how I specify seperator location, it will return an array that contains multiple elements. +const carsFromString = stringOfCars.split(','); console.log(carsFromString) +console.log(carsFromString.length) +//BONUS +// stringOfCars.split(); returns 1 +//stringOfCars.split(',');returns 8 +//---- + + +// `.reverse()` ---- +// * Use the `reverse` method to create an array `carsInReverse` which is the array `totalCars` in reverse. +// * Console.log `carsInReverse`. +// * Run the program. + +//this new array is the previous array backwards +const carsInReverse = totalCars.reverse(); +console.log(carsInReverse) +//---- + +// `.sort()`---- +// * Use the `sort` method to put the array `carsInReverse` into alphabetical order. +// * Based on the types of cars you used, predict which item in the array should be at index 0. +// * Use the following code to confirm or reject your prediction: `console.log(carsInReverse.indexOf('yourPrediction'));` + +//a new array with the cars in alphabetical order +//my prediction is that chevy will be at index zero. +const carsInAlph = carsInReverse.sort(); + +console.log(carsInAlph.indexOf('Chevy')) +console.log(carsInAlph) +//---- + + +// 1. `.slice()`---- +// * Use the `slice` method to create a `reptiles` array with `snake` and `lizard` from the `pets` array. +// * Console.log the `reptiles` array and run the program. +// * Now console.log the `pets` array and run the program. Why do you think `snake` and `lizard` are still in the original array? +// //an array for pets +const pets = ['dog', 'cat', 'fish', 'rabbit', 'snake', 'lizard', 'bird']; + +//a new array called reptiles. Reptiles are snake and lizard. Softwear engineer or zoologist? i am a man of many forms. +const reptiles = pets.slice(4, 6); + +console.log(reptiles) +console.log(pets) +//snake and lizard are still in the pets array, because splice() goes in to the referenced array, and retrieves the information from the specified index's. It then takes that information and turns it into a new array. Which i stored in a new object. //---- - +//. `.splice()` +// * Create a new array called `removedReptiles`, using the `splice` method to remove `snake` and `lizard` from the `pets` array. +// * Console.log `removedReptiles` and `pets` and run the program. +// Go back and add the string `'hamster'` in as a third parameter to your `splice` method, then run the program again and notice how the `pets` array has changed. Do you see how that works? +//take snake and lizard out of pets. store them as a new array in a new object + +const removedReptiles = pets.splice(4, 5,); +const removedReptilanBird = pets.splice(4, 5, 'Hamster'); -//NOTESFORREPL!!!!------------------------------- -//Concat()---- +console.log(removedReptiles) //From what i can tell, by adding the string "Hamster" as the third perameter, the computer heard me tell it to use the fifth index as the reference, the replace the index that follow with hamtser, and add the replaced element to the remove reptiles array. +console.log(pets) +//---- + + + +// `.pop()` +// * Use the `pop` method to remove the last item from the `pets` array, saving it to a variable called `removedPet`. +// * Console.log `removedPet` and `pets` and run the program. -// const array1 = ['a', 'b', 'c']; -// const array2 = ['d', 'e', 'f']; -// const array3 = array1.concat(array2); -// console.log(array3); +// take the last item out an array and turn it into a string. +const removedPet = pets.pop(); + + console.log(pets) +console.log(removedPet) //---- -//indexOf()---- -// const beasts = ['ant', 'bison', 'camel', 'duck', 'bison']; -// console.log(beasts.indexOf('bison')); -// // Expected output: 1 -// // Start from index 2 -// console.log(beasts.indexOf('bison', 2)); -// // Expected output: 4 -// console.log(beasts.indexOf('giraffe')); -// // Expected output: -1 -// //----- - -// //const animals = ['Dodo', 'Tiger', 'Penguin', 'Dodo']; -// console.log(animals.lastIndexOf('Dodo')); -// // Expected output: 3 -// console.log(animals.lastIndexOf('Tiger')); -// // Expected output: 1 -// ---- - -// const elements = ['Fire', 'Air', 'Water']; -// console.log(elements.join()); -// // Expected output: "Fire,Air,Water" -// console.log(elements.join('')); -// // Expected output: "FireAirWater" -// console.log(elements.join('-')); -// // Expected output: "Fire-Air-Water" -// ---- + + + + + + + + + + +//ARRAY METHODS From db903bb5d923feddc14407bdc60da54c3f6fead9 Mon Sep 17 00:00:00 2001 From: caglenoah Date: Thu, 20 Jul 2023 04:25:15 -0600 Subject: [PATCH 4/6] solved more challenges. still havent needed to use many resources, but when i have i knew exactly how to find it and apply it. --- main.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/main.js b/main.js index 7b6739b..536e2f3 100644 --- a/main.js +++ b/main.js @@ -143,6 +143,15 @@ console.log(removedPet) //---- + +// `.push()` +// - Use the `push` method to add `removedPet` back to the end of the `pets` array. +// - Console.log `pets` and run the program. + +//take an item out of a string and move it back to the end of thte arrray. +pets.push(removedPet); + +console.log(pets) From 3e1c69e82e69fc598c9ea298e3825b3022c7ff3a Mon Sep 17 00:00:00 2001 From: caglenoah Date: Thu, 20 Jul 2023 04:55:00 -0600 Subject: [PATCH 5/6] sfsfsf --- README.md | 5 ++++- main.js | 4 ++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a99fd77..9022a40 100644 --- a/README.md +++ b/README.md @@ -61,15 +61,18 @@ - Console.log `removedReptiles` and `pets` and run the program. - Go back and add the string `'hamster'` in as a third parameter to your `splice` method, then run the program again and notice how the `pets` array has changed. Do you see how that works? - 1. `.pop()` - Use the `pop` method to remove the last item from the `pets` array, saving it to a variable called `removedPet`. - Console.log `removedPet` and `pets` and run the program. 1. `.push()` - Use the `push` method to add `removedPet` back to the end of the `pets` array. - Console.log `pets` and run the program. + + 1. `.shift()` - Use the `shift` method to remove and console.log the first item in the `pets` array. + + 1. `.unshift()` - Use the `unshift` method to add the string `'turtle'` as the first item in the `pets` array. - Console.log the `pets` array and run the program. If all went according to plan, you should see `['turtle', 'cat', 'fish', 'rabbit', 'hamster', 'bird']`. diff --git a/main.js b/main.js index 536e2f3..5ee5193 100644 --- a/main.js +++ b/main.js @@ -152,6 +152,10 @@ console.log(removedPet) pets.push(removedPet); console.log(pets) +//---- + + + From 54fa20dd9660b4f0aa6677840a4207371c7b5d72 Mon Sep 17 00:00:00 2001 From: caglenoah Date: Thu, 20 Jul 2023 18:21:15 -0600 Subject: [PATCH 6/6] final commit --- README.md | 5 +---- main.js | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 52 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 9022a40..06e0354 100644 --- a/README.md +++ b/README.md @@ -67,15 +67,12 @@ 1. `.push()` - Use the `push` method to add `removedPet` back to the end of the `pets` array. - Console.log `pets` and run the program. - - 1. `.shift()` - Use the `shift` method to remove and console.log the first item in the `pets` array. - - 1. `.unshift()` - Use the `unshift` method to add the string `'turtle'` as the first item in the `pets` array. - Console.log the `pets` array and run the program. If all went according to plan, you should see `['turtle', 'cat', 'fish', 'rabbit', 'hamster', 'bird']`. + 1. `.forEach()` - Create a numbers array by copy/pasting the following: `const numbers = [23, 45, 0 , 2, 8, 44, 100, 1, 3, 91, 34]` - Write code that will add 2 to each item in the array `numbers`. diff --git a/main.js b/main.js index 5ee5193..0858d0f 100644 --- a/main.js +++ b/main.js @@ -122,8 +122,9 @@ console.log(pets) //take snake and lizard out of pets. store them as a new array in a new object -const removedReptiles = pets.splice(4, 5,); -const removedReptilanBird = pets.splice(4, 5, 'Hamster'); +const removedReptiles = pets.splice(4, 5,'Hamster'); + + console.log(removedReptiles) //From what i can tell, by adding the string "Hamster" as the third perameter, the computer heard me tell it to use the fifth index as the reference, the replace the index that follow with hamtser, and add the replaced element to the remove reptiles array. console.log(pets) @@ -155,12 +156,58 @@ console.log(pets) //---- +// `.shift()` +// - Use the `shift` method to remove and console.log the first item in the `pets` array. + +//get the first item out of the arrray +const firstItem = pets.shift(); + +console.log(firstItem) +console.log(pets) + //---- + + // `.unshift()` + // - Use the `unshift` method to add the string `'turtle'` as the first item in the `pets` array. + // - Console.log the `pets` array and run the program. If all went according to plan, you should see `['turtle', 'cat', 'fish', 'rabbit', 'hamster', 'bird']`. + +// + +//add a new string as the first item of the array +pets.unshift('Bird') +pets.unshift('Turtle'); +console.log(pets) +//---- + + +// `.forEach()` +// - Create a numbers array by copy/pasting the following: `const numbers = [23, 45, 0 , 2, 8, 44, 100, 1, 3, 91, 34]` +// - Write code that will add 2 to each item in the array `numbers`. +// - `forEach` requires a function to be passed into it as its first argument. +// - Build a function called `addTwo` that can take in num, index, and arr as parameters—`(num, index, arr)`—and returns `num + 2` at each `index` of the `arr`. +// - Use `.forEach()` on the `numbers` array, passing in your freshly built function `addTwo` as an argument, in order to add 2 to each number in the array. +// - Console.log `numbers` and run the program. + +//creating a numbers array +//creating an add two HOF +function addTwo(num, index, arr) { + return num + 2; +} + +const numbers = [23, 45, 0, 2, 8, 44, 100, 1, 3, 91, 34]; +const sumOfTwoArray = []; - +numbers.forEach((num, index, arr) => { + const newNum = addTwo(num, index, arr); + sumOfTwoArray.push(newNum) +}); +console.log(sumOfTwoArray) - +//i need to go into the array, get the item(number). add 2 to each individual index. +// use for reach() to access the individual arrays +// set a function as the forEach() parameters +//this function will need to add two numbers, i will need to do this first.