Java Reference
In-Depth Information
So, to sum up:
/(sugar )?candy|choc(olate|oholic)?/gi
reads as:
Au: close
up line
space
Either match zero or one occurrences of “sugar” followed by “candy.” Or alternatively match
“choc” followed by either one or zero occurrences of “olate” or match “choc” followed by zero or
one occurrence of “oholic.”
Finally, the following:
myString = myString.replace(myRegExp,"salad");
replaces the offending words with “salad” and sets myString to the new clean version:
"Mmm, I love salad, I'm a salad. I love salad too, sweet, salad."
Chapter 7
exercise 1 Question
Create a page that gets the user's date of birth. Then, using that information, tell her on what day of
the week she was born.
exercise 1 Solution
<!DOCTYPE html>
<html lang="en">
<head>
<title>Chapter 7: Question 1</title>
</head>
<body>
<script>
var days = ["Sunday", "Monday", "Tuesday", "Wednesday",
"Thursday", "Friday", "Saturday"];
var year = prompt("Enter the four digit year you were born.");
var month = prompt("Enter your birth month (1 - 12).");
var date = prompt("Enter the day you were born.");
var birthDate = new Date(year, month - 1, date);
alert(days[birthDate.getDay()]);
</script>
</body>
</html>
Save this as ch7 _ question1.html .
 
Search WWH ::




Custom Search