Question: I need help with this assignment in Java Script but using jQuery. / / Create a variable and assign an empty array to it .

I need help with this assignment in Java Script but using jQuery.
//Create a variable and assign an empty array to it.
//Set the focus to the DOM element that has an ID of itemID
//Assign a function named addToList to the click event of the element with ID of addBtn.
//Assign a function named removeFromList to the click event of the element with ID of removeBtn.
//Assign an anonymous function to the click event of the element with ID of clearListBtn.
/*
The anonymous function should do the following:
Clear the html of the element with ID of listID.
Reset the array variable to the empty array.
Clear the value of the input element with ID of itemID.
Get the same element to receive the focus.
*/
function addToList(e)
{
e.preventDefault();
//Declare a variable and assign it the value inside the form input element with ID of itemID.
//Check if the value of the variable is null or the empty string.
//If it is, just return from the function. That's all.
//Declare a variable and assign it the position of the variable in the array.
//Check the position value obtained from the last statement to see if it is equal to -1.
//If it IS NOT equal to -1, do the following:
/*
Call alert with a message stating that the item is already on the list.
Clear the value of the input element with ID of itemID.
Get the same element to receive the focus.
Return from this function.
*/
//Declare a variable and assing it a new li element.
//Set the text of the new li element to the value of the variable that has the data from the form. (You already declared this variable at the top of the function.)
//Append the new li element to the element with ID of listID.
//Add the data from the form that you got at the top of this function to the array.
//Clear the value of the input element with ID of itemID.
//Get the same element to receive the focus.
}
function removeFromList()
{
//Declare a variable and assign it the value inside the form input element with ID of itemID.
//Check if the value of the variable is null or the empty string.
//If it is, just return from the function. That's all.
//Declare a variable and assign it the position of the variable in the array.
//Check the position value obtained from the last statement to see if it is equal to -1.
//If it IS equal to -1, do the following:
/*
Call alert with a message stating that the item is NOT on the list. Include the item that was being looked for in the message.
Clear the value of the input element with ID of itemID.
Get the same element to receive the focus.
Return from this function.
*/
//Use the position of the element to remove it from the array.
//Clear the HTML of the element with ID of listID.
//Start a loop that will go through all of the items in the array.
//Inside the loop do the following:
/*
Create a new li element and assign it to a new variable.
Add the current value from the array to the text of the li element just created.
Append the li element to the element with ID of listID.
*/
//Clear the value of the input element with ID of itemID.
//Get the same element to receive the focus.
}
});

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 Programming Questions!