Table of Contents
Since this assignment was a class exercises, I shall not show you any model solutions.
Please write some JavaScript code that prints the following texts at the very bottom of the page:
The background-color of this document is xxx and the color is yyy.
The actual colors must come from reading the DOM. Make some tests showing that the printed colors change if you change them in the stylesheet. Make a simple page to test on, or use one of the pages from the first half of the course.
var y = document.getElementById('x');
y.innerHTML = "The background-color of this document is ";
y.innerHTML += document.getElementsByTagName('div')[0].style.backgroundColor;
y.innerHTML += " and the color is ";
y.innerHTML += document.getElementsByTagName('div')[0].style.color;
y.style.backgroundColor = 'red';
Please write the pseudocode for validating an email address,
given that you are not allowed to use regular expressions.
You must use the common format nn@mm.ll as the
pattern for a valid address.
We shall dive into validation of input data next week, so we shall use the pseudo code then.
/* * parse the entered string for an '@' * there must be text on both sides * * parse the left hand side for content, must not be empty * parse the right hand side for at least one '.' * non empty strings must come befor, after, and between the '.' * rightmost string must be two or more chars * * Programming hint: * Look for string.split(), and/or string.charAt() */