Dynamic Page Counters Coding Exercise JavaScript How to Challenge Learn to Code

Dynamic JavaScript DOM page counters Element Objects examples

Dynamically create page buttons that can be used to count totals separately.  Create a button to output all the result totals.  Only using JavaScript NO HTML elements

Dynamic Page counters with JavaScript :

  1. Create a global object to set the number of buttons to be created
  2. Create a main page element that will contain all the new elements
  3. Create a function to create page elements, adding the element type to a parent object.  Include a parameter in the function for the inner content of the element.
  4. Loop through and create all the buttons, set a default total of 0 for each one.  On click create a function that will update and output the current value of this element total.  You can add styling to the buttons
  5. Add a class of “btn” to each new button so that they can be distinguished from the main total tally button.   Create a button that will output all the current button total results.
  6. When the tally button is clicked create a function that will select all the elements with a class of “btn” and loop through them.
  7. For each element with the class of “btn” create a new list item element, output that into an unordered list on the main page.  The list item contents should show the element total and the element textContent.  You can also select the style to match the button style property values.

Do you want to learn more about JavaScript and how elements work.  They are objects which can hold values just like any other objects in JavaScript.   The three exercises below will demonstrate creating page elements with JavaScript, how to add values to the element objects, and how to update page elements.   There is also an exercise on how they work with the page element objects, and the difference between function expressions and function declarations. Course content web development and web design courses with coding examples and source code for the lesson content. Source Code is available within my Github account. Lessons posted are designed to help students learn more about a specific topic related to modern web development and applying code. Laurence Svekis is a professional top selling course author having instructed over 1 Million students both online and in person. Laurence Svekis is a Google Developer Expert specializing in Google Workspace automation using Google Apps Script Code.

Leave a Comment