-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathUnit3Assignment.html
More file actions
105 lines (77 loc) · 3.49 KB
/
Unit3Assignment.html
File metadata and controls
105 lines (77 loc) · 3.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<!doctype html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>WDV221 Intro Javascript</title>
<style>
div#container {
width:960px;
margin:auto;
padding:10px;
background-color:white;
border:thin solid black;
}
</style>
<script>
var studentName = ""; //global variable to be used later
var studentEmail = ""; //global variable to be used later
function displayGreeting() {
alert("Hello! Welcome to WDV221 Intro Javascript");
}
function getStudentName() {
studentName = prompt("Please enter your name");
}
function getStudentEmail(){
studentEmail = prompt("Please enter your student email")
}
function displayEmail(){
alert("Student Email: " + studentEmail)
}
function printStudentInfo(){
document.write("Student name:" + studentName);
document.write("<br>Student email:" + studentEmail);
}
function displayEmailName() {
var atSymbol = studentEmail.search("@"); //local variable that will store the location of the @ symbol
var emailNameOnly = studentEmail.substring(0,atSymbol); //local variable that will store the value of the name portion of the email address
alert( "Email name: " + emailNameOnly);
}
function displayEmailServer(){
let atSymbol = studentEmail.search("@");
let emailServer = studentEmail.substring(atSymbol + 1);
alert("Email Server: " + emailServer);
}
</script>
</head>
<body>
<div id="container">
<h1>WDV221 Intro Javascript</h1>
<h2>Unit-3 Functions</h2>
<p>Tasks: </p>
<p>1. Run the displayGreeting( ) as a run time script. </p>
<script>displayGreeting()</script>
<p>2. Run the getStudentName( ) as a run time script.</p>
<script>getStudentName()</script>
<p>3. Write a function called getStudentEmail( ). The function should use the prompt( ) to ask the user to enter their DMACC Email address. Store the returned valued in the studentEmail variable that has already been defined.</p>
<p>4. Run the getStudentEmail( ) as a run time script.</p>
<script>getStudentEmail()</script>
<p>5. Write a function called displayEmail( ). The function will display the studentEmail variable with a message "Student Email:" in an alert. The button below will call the function when clicked.</p>
<p>
<input type="button" name="button" id="button" value="Display Email" onClick="displayEmail()">
</p>
<p>6. Complete the function called printStudentInfo( ). The function should write the studentName and studentEmail to the web page. Each in their own paragraph. </p>
<p><script>printStudentInfo()</script></p>
<p>7. Complete the displayEmailName( ). The function should display the name portion of the studentEmail variable. Do not include the @ symbol in the result. </p>
<p>Modify the following button to call the displayEmailName( ) with a click event handler.</p>
<p>
<input type="button" name="button2" id="button2" value="Display Email Name" onclick="displayEmailName()">
</p>
<p>8. Write a function called displayEmailServer( ). The function will display that portion of the studentEmail that follows the @ symbol. Do not include the @ symbol in the result.</p>
<p>9. Fix the button element that will run the displayEmailServer( ) with a click event handler.</p>
<p>
<input type="button" name="button3" id="button3" value="Display Email Server" onclick="displayEmailServer()">
</p>
<p> </p>
</div>
<h2> </h2>
</body>
</html>