Question: Purpose The purpose of this assignment is to utilize basic JavaScript, as learned in this class, to show knowledge on objects functions, variables, and more.
Purpose
The purpose of this assignment is to utilize basic JavaScript, as learned in this class, to show knowledge on objects functions, variables, and more.
Tasks
Credit Card Validation
You're starting your own credit card business. You've come up with a new way to validate credit cards with a simple function called validateCreditCard that returns true or false.
Here are the rules for a valid number:
Number must be digits, all of them must be numbers
You must have at least two different digits represented all of the digits cannot be the same
The final digit must be even
The sum of all the digits must be greater than
The following credit card numbers are valid:
The following credit card numbers are invalid:
ac invalid characters
only one type of number
sum less than
odd final number
Hint: Remove the dashes from the input string before checking if the input credit card number is valid. check out split and join methods.
points extra: Make your credit card scheme even more advanced! What are the rules, and what are some numbers that pass or fail? Ideas: check the expiration date! Check out the Luhn Algorithm for inspiration.
The Cash Register
Implement a class called Item
Item class should have the following fields: name, price
Implement a class called ShoppingCart
ShoppingCart class should have an array of items
ShoppingCart class should a method called addItem, which adds a new item to the shopping cart. The addItem method should accept one argument eg item and it should add that item into the array.
Write a function called that accepts a ShoppingCart object. The function should return the total price of the shopping cart. This function should be outside of both ShoppingCart and Item classes.
Create multiple instances of the shopping cart object and show the results for each instance in your choice of display.
Examples:
Here are a few examples of unit tests
const item new Itemapple; apple is the name, is the price
const item new Itemcarrot;
const item new Itemshirt;
const cart new ShoppingCart;
cart.addItemitem;
cart.addItemitem;
cart.addItemitem;
Bonus Extra points: Update your Shopping Cart Object to add a taxable field to each item in the cart. Update your cashRegister function to apply tax to the taxable items only, and outputs the correct total. Create multiple instances of the shopping cart object and show the results for each instance in your choice of display.
Acceptance Criteria
Your code must be appropriately commented. Any variables, functions, objects, or algorithms that are not obvious, must be commented on
Your code must output the required output.
Completion
submit JavaScript files with the name lastnamefirstnameassignmentjs or copy and paste your code into Canvas so that your instructor can run them successfully in Visual Studio Code. No HTML is needed for this assignment. You can use the console.log to test your program.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
