Giter Site home page Giter Site logo

prime-pw-week-4-assignment-part-3's Introduction

Tier 1 Week 4 - Part 3

This week we'll be pulling together all of the Javascript techniques you've learned thus far as well as practicing with HTML & CSS.

Topics Covered

  • variables
  • arrays
  • conditionals
  • functions
  • HTML & CSS

Assignment - Cart System

In this section we will write some functions that might be used in a simple cart system for a store.

Required Features

Update the cart.js file to do the following:

  • Create a global variable named basket and set it to an empty array.

  • Create a function called addItem. It should:

    • take an input parameter for a string item
    • add the new item to the global array basket.
    • return true indicating the item was added
  • Create a function called listItems. It should:

    • loop over the items in the basket array
    • console.log each individual item on a new line
  • Create a function called empty. It should:

    • reset the basket to an empty array

IMPORTANT Make sure that you are writing code in the file to test every function that you write!

For example, to test addItem:

console.log(`Basket is ${basket}`);
console.log('Adding apples (expect true)', addItem('apples'));
console.log(`Basket is now ${basket}`);

Stretch Goals

Remember that Stretch Goals are not required, but will help you to further develop concepts from the skills we have covered.

Using functions in other functions!

  1. Add a global const named maxItems and set it to 5.

  2. Create a function called isFull(). It should:

  • return false if the basket contains less than max number of items
  • return true otherwise (equal or more than maxItems)
  1. Update the required addItem function to:
  • Use the isFull function to prevent more than maxItems from being added to the basket.
  • If an item was added to the array, return true
  • If there was no room and the item could not be added return false

Using Array built-in functions!

  1. Create a function called removeItem. It should:
  • Take an input parameter for a string item
  • Use Array.indexOf to find the index of the first matching item in the basket.
  • Use Array.splice to remove the first matching item from the basket.
  • Return the item removed or null if the item was not found

Assignment Submission

Check in your repo, then turn in your work via the Prime Academy Assignment Application at http://primeacademy.io, as usual and don't hesitate to hit up the Slack channel as needed!

REMINDER: Make sure to answer the Slack discussion question for this week!

prime-pw-week-4-assignment-part-3's People

Contributors

kdszafranski avatar mbmosman avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.