Skip to content
Intern–Middle163 views

Timer-based text change in an element

Task condition

It is necessary to create a function that every two seconds replaces the content of a specified HTML element with the next element from a given array of strings and automatically stops after ten seconds.

/**
 * It is required to write a function that updates
 * the text of an element with the next array element
 * every 2 seconds, and stops after 10 seconds
 */
function updateTextEveryTwoSeconds(elementId, texts) {
}

// Example usage
updateTextEveryTwoSeconds("content", [
  "Hello world 1",
  "Hello world 2",
  "Hello world 3",
  "Hello world 4",
  "Hello world 5",
]);
Frontend tasks in the code trainer