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("\n");
}
// 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();
};
<html>
<body>
<button onclick="splitInputstring ()">Try it</button>
<script type="text/javascript">
window.entry = prompt("Enter the entry");// Create a Prompt box for input number of entry
function splitInputstring (){ // split function
window.Splitstr; // global variable
var tr=[]; // variable declaration
if(entry==1){ // condetion for entry==1
var Str = prompt("Enter the string"); // Create a Prompt box for input string
Splitstr = Str.split(""); // Split the string
for(i = 0; i < Splitstr.length; i++)
{
document.write("<br /> Element " + i + " of the array is: " + Splitstr[i]);
}
}
if(entry>1){ // condetion for entry>1
for(i = 0; i < entry; i++){
var Str1=[]; // variable declaration
tr[i] = prompt("Enter the string"); // Create a Prompt box for take multiple string as input
alert(tr[i]); // print input string in alert box
Str1 =Str1+tr[i]; // concatenat the multiple string
document.write(Str1); // print concatenat string
}
}
}
</script>
</body>
</html>
Note- when you run this code first one prompt box will come for ask number entry.Then one "Try It" button will come, you just click it for taking input string.Again prompet will come for the input string.If entry ==1 then input string will split.If entry >1 then prompt will come for input string and the alert box will print input string.For entry>1 case result will print only concatenate a string.
Use the split method of the string object to convert the user's entry into an array....
JavaScript (Please debug this code) When a user enters a string in the input box, the program is designed to add the string to an array. When the array reaches a certain length, the program displays all the users' entries in a list on the page. When you finish debugging, the user's entry in the input box should be cleared each time the submit button is clicked. Additionally, after five strings are submitted, the entire list of submitted strings should...
Need Help correcting last function runHanoi(A,C,B) so this program correctly calculates number of moves made. Solving the Hanoi tower. Please post correct Javascript. This is used in jsfiddle. HTML: html> <schript src="TowerOfHanoi.js"</script> </script> <h1> Tower of Hanoi </h1> Enter the number of disks (Disk amount must be < 7): <br> <br> <input id = 'uInput' type = 'textbox' size = 10 > <button id = 'setup' onClick = 'insertDisks()'> Set up Tower of Hanoi </button> <button id=calc onClick = 'runHanoi(stackA,...
javascript questions
Declare an empty deck array. Use a loop to fill the array with
string values that represent the 52 cards of a normal deck. The
numbers go from 1 to 13 with 1 for an ace, 11 for a jack, 12 for a
queen, and 13 for a king. The suits are C for clubs, D for
diamonds, H for hearts, and S for spades. Here’s the list of 52
values:
1C, …, 13C, 1D, …, 13D, 1H,...
<!DOCTYPE html> <html> <head> <!-- JavaScript 6th Edition Chapter 4 Hands-on Project 4-3 Author: Date: Filename: index.htm --> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Hands-on Project 4-3</title> <link rel="stylesheet" href="styles.css" /> <script src="modernizr.custom.05819.js"></script> </head> <body> <header> <h1> Hands-on Project 4-3 </h1> </header> <article> <div id="results"> <p id="resultsExpl"></p> <ul> <li id="item1"></li> <li id="item2"></li> <li id="item3"></li> <li id="item4"></li> <li id="item5"></li> </ul> </div> <form> <fieldset> <label for="placeBox" id="placeLabel"> Type the name of a place, then click Submit: </label> <input type="text" id="placeBox"...
In this exercise, you’ll upgrade a version of the MPG
application so the error messages are displayed in span elements to
the right of the text boxes.
Open the HTML and JavaScript files in this folder:
exercises_short\ch06\mpg\
Then, run the application and click the Calculate MPG button to
see that an error message is displayed in an alert dialog box for
each of the two input fields.
2. In the HTML file, add a span element after the input element...
Develop the Change Calculator application In this exercise, you’ll create an application that displays the minimum number of quarters, dimes, nickels, and pennies that make up the number of cents specified by the user. Without the use of a JavaScript Library (for coins). 1. Open the HTML and JavaScript files below: 2. In the JavaScript file, note that three functions are supplied. The $ function. The start of a calculateChange function. And an onload event handler that attaches the calculateChange...
Add JavaScript code in the “find_primeV2.js” to allow users to enter a number, and then based on the number of user enters, to find out how many prime numbers there are up to and including the user inputted number and then display them on the web page. The following are the detailed steps to complete this assignment: Step 1. [30 points] In “find_primeV2.js”, complete isPrime() function by (1) Adding one parameter in function header. That parameter is used to accept...
Create an HTML5 page that contains a form to collect the following data. The text in bold indicates the id value that should be assigned to each html control: Product (drop down list) product – iPad, iPhone 6S, Galaxy 5S, Moto X, and so on Quantity (number) quantity Unit price (number) unit_price Discount (%)(number) discount_rate Date (date) order_date First Name (text box) first_name Last Name (text box) last_name Payment type (drop down list) payment_type – Visa, Master, Discover, Amex, and...
QUOTE OF THE DAY not totally working in JAVA I need to fix this code, the problem that I have is that I have to include before the listed quotes , one of the quotes and the date and later are the listed quotes. Now when I run it , it only shows the title and the list of quotes. I have been trying to figure out the problem, any help...? I need it to run the title "Quote of...
I have the code buts its not working as this below instruction can anyone help Use the requirements from the pizza part of Assignment 6 and do the following using CSS and an internal style sheet: 1. Your Javascript function should be in an external file (don’t forget to move it up to studentweb too) 2. Put a red border of 300px in width around the form 3. There should be three Div sections: header, main_body, and footer. 4. Center the name of your...