Declare a variable named thisTime containing a Date object for February 3, 2018 at 03:15:28 AM. Use the toLocaleString() method to save the text of the thisTime variable in the timeStr variable. Change the inner HTML code of the page element with the ID "timeStamp" to the value of the timeStr variable.

Respuesta :

Answer:

test.js

  1. let thisTime = new Date(2018, 1, 3, 3, 15, 28, 0);
  2. let timeStr = thisTime.toLocaleString();
  3. document.getElementById("timeStamp").innerHTML = timeStr;

Explanation:

In test.js file, create a Date object with specified date and time. We can specify seven numbers: year, month, day, hour, minute, second and miliseconds for the Date object (Line 1) and assign it to thisTime variable.

Next, use toLocaleString method to convert the date to string and assign it to timeStr variable (Line 2).

Lastly, use document getElementById method to create a reference object and point it to HTML element with id "timeStamp" and set the timeStr to its innerHTML property (Line 3). This will display the time string to the web page. We should see 2/3/2018, 3:15:28 AM displayed on the web page.