├── .gitignore ├── challenges ├── index.html ├── classes.js ├── closure.js ├── prototypes.js └── arrays-callbacks.js └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | -------------------------------------------------------------------------------- /challenges/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Sprint Challenge 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 |

Sprint Challenge - Check your work in the console!

18 | 19 | 20 | -------------------------------------------------------------------------------- /challenges/classes.js: -------------------------------------------------------------------------------- 1 | // 1. Copy and paste your prototype in here and refactor into class syntax. 2 | 3 | // Test your volume and surfaceArea methods by uncommenting the logs below: 4 | // console.log(cuboid.volume()); // 100 5 | // console.log(cuboid.surfaceArea()); // 130 6 | 7 | // Stretch Task: Extend the base class CuboidMaker with a sub class called CubeMaker. Find out the formulas for volume and surface area for cubes and create those methods using the dimension properties from CuboidMaker. Test your work by logging out your volume and surface area. -------------------------------------------------------------------------------- /challenges/closure.js: -------------------------------------------------------------------------------- 1 | // ==== Closures ==== 2 | 3 | /* Task 1: Study the code below and explain in your own words why nested function can access the variable internal. */ 4 | 5 | 6 | const external = "I'm outside the function"; 7 | 8 | function myFunction() { 9 | console.log(external); 10 | const internal = "Hello! I'm inside myFunction!"; 11 | 12 | function nestedFunction() { 13 | console.log(internal); 14 | }; 15 | nestedFunction(); 16 | } 17 | myFunction(); 18 | 19 | // Explanation: 20 | 21 | 22 | /* Task 2: Counter */ 23 | 24 | /* Create a function called `sumation` that accepts a parameter and uses a counter to return the summation of that number. For example, `summation(4)` should return 10 because 1+2+3+4 is 10. */ 25 | -------------------------------------------------------------------------------- /challenges/prototypes.js: -------------------------------------------------------------------------------- 1 | /* ===== Prototype Practice ===== */ 2 | 3 | // Task: You are to build a cuboid maker that can return values for a cuboid's volume or surface area. Cuboids are similar to cubes but do not have even sides. Follow the steps in order to accomplish this challenge. 4 | 5 | /* == Step 1: Base Constructor == 6 | Create a constructor function named CuboidMaker that accepts properties for length, width, and height 7 | */ 8 | 9 | 10 | /* == Step 2: Volume Method == 11 | Create a method using CuboidMaker's prototype that returns the volume of a given cuboid's length, width, and height 12 | 13 | Formula for cuboid volume: length * width * height 14 | */ 15 | 16 | 17 | /* == Step 3: Surface Area Method == 18 | Create another method using CuboidMaker's prototype that returns the surface area of a given cuboid's length, width, and height. 19 | 20 | Formula for cuboid surface area of a cube: 2 * (length * width + length * height + width * height) 21 | */ 22 | 23 | 24 | /* == Step 4: Create a new object that uses CuboidMaker == 25 | Create a cuboid object that uses the new keyword to use our CuboidMaker constructor 26 | Add properties and values of length: 4, width: 5, and height: 5 to cuboid. 27 | */ 28 | 29 | // Test your volume and surfaceArea methods by uncommenting the logs below: 30 | // console.log(cuboid.volume()); // 100 31 | // console.log(cuboid.surfaceArea()); // 130 32 | 33 | 34 | -------------------------------------------------------------------------------- /challenges/arrays-callbacks.js: -------------------------------------------------------------------------------- 1 | // ==== ADVANCED Array Methods ==== 2 | 3 | // Given this zoo data from around the United States, follow the instructions below. Use the specific array methods in the requests below to solve the problems. 4 | 5 | const zooAnimals = [ 6 | { animal_name: "Jackal, asiatic", population: 5, scientific_name: "Canis aureus", state: "Kentucky" }, 7 | { animal_name: "Screamer, southern", population: 1, scientific_name: "Chauna torquata", state: "Alabama" }, 8 | { animal_name: "White spoonbill", population: 8, scientific_name: "Platalea leucordia", state: "Georgia" }, 9 | { animal_name: "White-cheeked pintail", population: 1, scientific_name: "Anas bahamensis", state: "Oregon" }, 10 | { animal_name: "Black-backed jackal", population: 2, scientific_name: "Canis mesomelas", state: "Washington" }, 11 | { animal_name: "Brolga crane", population: 9, scientific_name: "Grus rubicundus", state: "New Mexico" }, 12 | { animal_name: "Common melba finch", population: 5, scientific_name: "Pytilia melba", state: "Pennsylvania" }, 13 | { animal_name: "Pampa gray fox", population: 10, scientific_name: "Pseudalopex gymnocercus", state: "Connecticut" }, 14 | { animal_name: "Hawk-eagle, crowned", population: 10, scientific_name: "Spizaetus coronatus", state: "Florida" }, 15 | { animal_name: "Australian pelican", population: 5, scientific_name: "Pelecanus conspicillatus", state: "West Virginia" }, 16 | ]; 17 | 18 | /* Request 1: .forEach() 19 | 20 | The zoos want to display both the scientific name and the animal name in front of the habitats. Populate the displayNames array with only the animal_name and scientific_name of each animal. displayNames will be an array of strings, and each string should follow this pattern: "Name: Jackal, asiatic, Scientific: Canis aureus." 21 | 22 | */ 23 | const displayNames = []; 24 | console.log(displayNames); 25 | 26 | /* Request 2: .map() 27 | 28 | The zoos need a list of all their animal's names (animal_name only) converted to lower case. Using map, create a new array of strings named lowCaseAnimalNames, each string following this pattern: "jackal, asiatic". Log the resut. 29 | 30 | */ 31 | 32 | const lowCaseAnimalNames = []; 33 | console.log(lowCaseAnimalNames); 34 | 35 | /* Request 3: .filter() 36 | 37 | The zoos are concerned about animals with a lower population count. Using filter, create a new array of objects called lowPopulationAnimals which contains only the animals with a population less than 5. 38 | 39 | */ 40 | const lowPopulationAnimals = []; 41 | console.log(lowPopulationAnimals); 42 | 43 | /* Request 4: .reduce() 44 | 45 | The zoos need to know their total animal population across the United States. Find the total population from all the zoos using the .reduce() method. Remember the reduce method takes two arguments: a callback (which itself takes two args), and an initial value for the count. 46 | 47 | */ 48 | let populationTotal = 0; 49 | console.log(populationTotal); 50 | 51 | 52 | // ==== Callbacks ==== 53 | 54 | /* Step 1: Create a higher-order function 55 | * Create a higher-order function named consume with 3 parameters: a, b and cb 56 | * The first two parameters can take any argument (we can pass any value as argument) 57 | * The last parameter accepts a callback 58 | * The consume function should return the invocation of cb, passing a and b into cb as arguments 59 | */ 60 | 61 | 62 | /* Step 2: Create several functions to callback with consume(); 63 | * Create a function named add that returns the sum of two numbers 64 | * Create a function named multiply that returns the product of two numbers 65 | * Create a function named greeting that accepts a first and last name and returns "Hello first-name last-name, nice to meet you!" 66 | */ 67 | 68 | 69 | /* Step 3: Check your work by un-commenting the following calls to consume(): */ 70 | // console.log(consume(2, 2, add)); // 4 71 | // console.log(consume(10, 16, multiply)); // 160 72 | // console.log(consume("Mary", "Poppins", greeting)); // Hello Mary Poppins, nice to meet you! 73 | 74 | 75 | 76 | 77 | /* 78 | 79 | Stretch: If you haven't already, convert your array method callbacks into arrow functions. 80 | 81 | */ 82 | 83 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Sprint Challenge: JavaScript Fundamentals 2 | 3 | This challenge allows you to practice the concepts and techniques learned over the past week and apply them in a survey of problems. This Sprint explored JavaScript Fundamentals. During this Sprint, you studied array methods, this keyword, prototypes, and class syntax. In your challenge this week, you will demonstrate proficiency by completing a survey of JavaScript problems. 4 | 5 | ## Instructions 6 | 7 | **Read these instructions carefully. Understand exactly what is expected _before_ starting this Sprint Challenge.** 8 | 9 | This is an individual assessment. All work must be your own. Your challenge score is a measure of your ability to work independently using the material covered through this sprint. You need to demonstrate proficiency in the concepts and objectives introduced and practiced in preceding days. 10 | 11 | You are not allowed to collaborate during the Sprint Challenge. However, you are encouraged to follow the twenty-minute rule and seek support from your TL and Instructor in your cohort help channel on Slack. Your work reflects your proficiency in JavaScript fundamentals. 12 | 13 | > You have three hours to complete this challenge. Plan your time accordingly. 14 | 15 | ## Description 16 | 17 | You will notice there are several JavaScript files being brought into the index.html file. Each of those files contain JavaScript problems you need to solve. If you get stuck on something, skip over it and come back to it later. 18 | 19 | In meeting the minimum viable product (MVP) specifications listed below, you should have a console full of correct responses to the problems given. 20 | 21 | ## Self-Study Questions 22 | 23 | Demonstrate your understanding of this week's concepts by answering the following free-form questions. 24 | 25 | Edit this document to include your answers after each question. Make sure to leave a blank line above and below your answer so it is clear and easy to read by your team lead 26 | 27 | 1. Briefly compare and contrast `.forEach` & `.map` (2-3 sentences max) 28 | 29 | 2. Explain the difference between a callback and a higher order function. 30 | 31 | 3. What is closure? 32 | 33 | 4. Describe the four rules of the 'this' keyword. 34 | 35 | 5. Why do we need super() in an extended class? 36 | 37 | ### Task 1 - Project Set up 38 | 39 | Follow these steps to set up and work on your project: 40 | Make sure you clone the branch that the TK links to: the vnext branch, NOT master! 41 | 42 | - [ ] Create a forked copy of this project. 43 | - [ ] Add TL as collaborator on Github. 44 | - [ ] Clone your OWN version of Repo (Not Lambda's by mistake!). 45 | - [ ] Create a new Branch on the clone: git checkout -b ``. 46 | - [ ] Create a pull request before you start working on the project requirements. You will continuously push your updates throughout the project. 47 | - [ ] You are now ready to build this project with your preferred IDE 48 | - [ ] Implement the project on your Branch, committing changes regularly. 49 | - [ ] Push commits: git push origin ``. 50 | 51 | 52 | 53 | ### Task 2 - Minimum Viable Product 54 | 55 | Your finished project must include all of the following requirements: 56 | 57 | **Pro tip for this challenge: If something seems like it isn't working locally, copy and paste your code up to codepen and take another look at the console.** 58 | 59 | #### Task A: Objects and Arrays 60 | 61 | Test your knowledge of advanced array methods and callbacks. 62 | * [ ] Use the [arrays-callbacks.js](challenges/arrays-callbacks.js) link to get started. Read the instructions carefully! 63 | 64 | #### Task B: Closure 65 | 66 | This challenge takes a look at closures as well as scope. 67 | * [ ] Use the [closure.js](challenges/closure.js) link to get started. Read the instructions carefully! 68 | 69 | #### Task C: Prototypes 70 | 71 | Create constructors, bind methods, and create cuboids in this prototypes challenge. 72 | * [ ] Use the [prototypes.js](challenges/prototypes.js) link to get started. Read the instructions carefully! 73 | 74 | #### Task D: Classes 75 | 76 | Once you have completed the prototypes challenge, it's time to convert all your hard work into classes. 77 | * [ ] Use the [classes.js](challenges/classes.js) link to get started. Read the instructions carefully! 78 | 79 | In your solutions, it is essential that you follow best practices and produce clean and professional results. Schedule time to review, refine, and assess your work and perform basic professional polishing including spell-checking and grammar-checking on your work. It is better to submit a challenge that meets MVP than one that attempts too much and does not. 80 | 81 | ### Task 3 - Stretch Problems 82 | 83 | There are a few stretch problems found throughout the files, don't work on them until you are finished with MVP requirements! 84 | 85 | ## Submission Format 86 | 87 | Follow these steps for completing your project: 88 | 89 | - [ ] Submit a Pull-Request to merge Branch into master (student's Repo). 90 | - [ ] Add your team lead as a Reviewer on the Pull-request 91 | - [ ] TL then will count the HW as done by merging the branch back into master. 92 | --------------------------------------------------------------------------------