Question: Use the split method of the string object to convert the user's entry into an array. If there is more than one task in the

Use the split method of the string object to convert the user's entry into an array. If there is more than one task in the entry, use the concat method of the tasks array to add the new tasks to the tasks array. This is what I have been working with.

"use strict"; var $ = function(id) { return document.getElementById(id); };

var tasks = [];

var displayTaskList = function() { var list = ""; // if there are no tasks in tasks array, check storage if (tasks.length === 0) { // get tasks from storage or empty string if nothing in storage var storage = localStorage.getItem("tasks") || "";

// if not empty, convert to array and store in global tasks variable if (storage.length > 0) { tasks = storage.split("|"); } } // if there are tasks in array, sort and create tasks string if (tasks.length > 0) { tasks.sort(); list = tasks.join(" "); } // display tasks string and set focus on task text box $("task_list").value = list; $("task").focus(); };

var addToTaskList = function() { var task = $("task"); if (task.value === "") { alert("Please enter a task."); } else { // add tasks to array and local storage var newTasks = tasks.split(","); var nameTasks = newTasks.concat(","); alert (nameTasks.length); alert (nameTasks);

// clear task text box and re-display tasks task.value = ""; displayTaskList(); } };

var clearTaskList = function() { tasks.length = 0; localStorage.tasks = ""; $("task_list").value = ""; $("task").focus(); };

window.onload = function() { $("add_task").onclick = addToTaskList; $("clear_tasks").onclick = clearTaskList; displayTaskList(); };

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!