Page 250 - Web_Application_v2.0_C12_Fb
P. 250

if (index !== -1) {
                   carList.splice(index, 1);
                   alert(carToDelete + " has been deleted from the list.");
                   } else {
                   alert("Car not found in the list.");
                   }
                   } else {
                   alert("The list is empty. No cars to delete.");
                   }}
                   function showTotalCars() {
                   alert("Total number of cars: " + carList.length);
                   }
                   function showAllCars() {
                   if (carList.length > 0) {
                   alert("Car names in the list:\n" + carList.join("\n"));
                   } else {
                   alert("The list is empty.");
                   }}
                   function exitProgram() {
                   alert("Exiting the program. Goodbye!");
                   document.body.innerHTML = "<h1>Program exited.</h1>";
                   }
                   </SCRIPT>
                   </BODY>

                   </HTML>
               When you execute this code the following output appears:





















               Now, perform the following tasks:
               1.  Add a car to the list

                 For this perform the following steps:
                 i.  Click on the Add a Car to the list link.
                 ii.  Enter car name and click on the OK button.
                      A message appears that shows car added successfully.


                248   Touchpad Web Applications (Ver. 2.0)-XII
   245   246   247   248   249   250   251   252   253   254   255