Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Help with JSON and JavaScript...I have the other files but I only need help on this. Let me know if you want to see the

Help with JSON and JavaScript...I have the other files but I only need help on this. Let me know if you want to see the rest.

1. Add code to the getContacts method that creates a function named reviver. Code the reviver method so it adds dashes back to regular phone numbers (7 characters), phone numbers with area codes (10 characters), and phone numbers with 1 + area code (11 characters). Then, use the reviver function with the parse method.

2. add code to the setContacts method that creates a function named replacer. Code the replacer function so it strips all non-numeric characters from the phone number value. Then, use the replacer function with the stringify method.

"use strict";

var storage = { keyContacts: "contacts_1", getContacts: function() { // get string from local storage var storageString = localStorage.getItem(this.keyContacts) || null; // convert string to JavaScript object and return, or return empty array if string is null return JSON.parse(storageString) || []; }, setContacts: function(value) { // convert JavaScript object to string var storageString = JSON.stringify(value); // store string in local storage localStorage.setItem(this.keyContacts, storageString); }, clearContacts: function() { localStorage.setItem(this.keyContacts, ""); } };

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Making Databases Work The Pragmatic Wisdom Of Michael Stonebraker

Authors: Michael L. Brodie

1st Edition

1947487167, 978-1947487161

Students also viewed these Databases questions