Add JS to HTML
- Directly in HTML
- External script
Write a function that returns the sum of a given array.
Write a function that checks if a given string is a valid e-mail address.
HINT: /^\w+([.-]?\w+)@\w+([.-]?\w+)(.\w{2,3})+$/
Given the following array of objects, write a function that prints the status at a given index:
var library = [
{
author: 'Bill Gates',
title: 'The Road Ahead',
readingStatus: true
},
{
author: 'Steve Jobs',
title: 'Walter Isaacson',
readingStatus: true
},
{
author: 'Suzanne Collins',
title: 'Mockingjay: The Final Book of The Hunger Games',
readingStatus: false
}];
Given the following cart containing an array of items:
var cart = [
{
name: 'Shoes',
price: 560,
quantity: 4
},
{
name: 'Regular Tees',
price: 455.50,
quantity: 6
},
{
name: 'Socks',
price: 65.99,
quantity: 2
}];
a) Write a function that takes a new item and adds it to the cart.
b) Write a function that sorts the cart items by a given property.
c) Create a function called findByName( name ) that will return an array of matching items for the searched name.
d) Write a function that returns the total cost of the items in the cart.