Question: 1. Open the HTML and JavaScript files in this folder: exercises_shortch11task_manager 2. In the library for native objects (library_native_object.js), code a new method called isBlank
1. Open the HTML and JavaScript files in this folder: exercises_short\ch11\task_manager\
2. In the library for native objects (library_native_object.js), code a new method called isBlank on the String objects prototype. The new method should check whether the strings value is an empty string and return true if it is, false if it isnt.
3. In the storage and task library files (library_storage.js and library_task.js), find every place that the code checks whether a strings value is an empty string and rewrite it to use the new isBlank method.
library_native_object.js:
"use strict";
String.prototype.capitalize = String.prototype.capitalize || function() { var first = this.substring(0,1); return first.toUpperCase() + this.substring(1); };
library_storage.js:
"use strict";
var localStoragePrototype = { get: function() { return localStorage.getItem(this.key); }, set: function(str) { localStorage.setItem(this.key, str); }, clear: function() { localStorage.setItem(this.key, ""); } };
var stringArrayStoragePrototype = Object.create(localStoragePrototype); // inherit stringArrayStoragePrototype.get = function() { var str = localStoragePrototype.get.call(this) || ""; return (str === "")? []: str.split("|");
}; stringArrayStoragePrototype.set = function(arr) { if (Array.isArray(arr)) { var str = arr.join("|"); localStoragePrototype.set.call(this, str);
} };
var getTaskStorage = function(key) { var storage = Object.create(stringArrayStoragePrototype); // inherit storage.key = key; // add own property return storage; };
library_task.js:
"use strict";
var Task = function(task) { this.text = task; }; Task.prototype.isValid = function() { if (this.text === "") { return false; } else { return true; } };
Task.prototype.toString = function() { // capitalize return this.text.capitalize();
//var first = this.text.substring(0,1);
//return first.toUpperCase() + this.text.substring(1); };
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
