Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

6.8.2: Using Date methods. Assign daysPassed with the number of days passed sinc

ID: 3911425 • Letter: 6

Question

6.8.2: Using Date methods.

Assign daysPassed with the number of days passed since the world wide web was born and today. Hint: 1000 milliseconds are in a second, 60 seconds are in a minute, etc.

var interestingEvents = {
"Long distance telegraph": new Date(1844, 4, 24),
"First telephone call": new Date(1876, 2, 10),
"Microsoft founded": new Date(1975, 3, 4),
"World wide web born": new Date(1989, 2, 1),
"Google founded": new Date(1998, 8, 4),
"Facebook website launch": new Date(2004, 1, 4)
};
var interestingDate = interestingEvents["World wide web born"]; // Code also tested using date of First telephone call
var daysPassed = 0;

/* Your solution goes here */

___________________________________________________________________

7.3.1: Event-driven programming.

Register the countChars event handler to handle focus changes for the textarea tag. Note: The function counts the number of characters in the textarea.

var textareaElement = document.getElementById("studentName");

function countChars(event) {
document.getElementById("stringLength").innerHTML = event.target.value.length;
}

/* Your solution goes here */

___________________________________________________________________

7.4.1: Form validation.

Use HTML5 validation attributes to ensure the entered age is between 18 and 120, inclusive, and the user name is 20 characters or less.

<form>
<label for="userAge">User Age:</label>
<input id="userAge" type="number" name="age"><br>
<label for="userName">User Name:</label>
<input id="userName" type="text" name="username"><br>
<input type="submit">
</form>

Explanation / Answer

If you have any doubts, please give me comment...

6.8 .2:

var interestingEvents = {

"Long distance telegraph": new Date(1844, 4, 24),

"First telephone call": new Date(1876, 2, 10),

"Microsoft founded": new Date(1975, 3, 4),

"World wide web born": new Date(1989, 2, 1),

"Google founded": new Date(1998, 8, 4),

"Facebook website launch": new Date(2004, 1, 4)

};

var interestingDate = interestingEvents["World wide web born"]; // Code also tested using date of First telephone call

var daysPassed = 0;

/* Your solution goes here */

daysPassed = (Math.round((new Date() - interestingDate) / (1000 * 60 * 60 * 24)))-1;

7.3.1

var textareaElement = document.getElementById("studentName");

function countChars(event) {

document.getElementById("stringLength").innerHTML = event.target.value.length;

}

/* Your solution goes here */

textareaElement.onchange = function(e){

countChars(e);

};

7.4.1

<form>

<label for="userAge">User Age:</label>

<input id="userAge" type="number" name="age" min="18" max = "120"><br>

<label for="userName">User Name:</label>

<input id="userName" type="text" name="username" maxlength="20"><br>

<input type="submit">

</form>