-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpart3.html
More file actions
197 lines (181 loc) · 7.29 KB
/
part3.html
File metadata and controls
197 lines (181 loc) · 7.29 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
<!DOCTYPE html>
<html lang="en">
<head>
<!--Kristian Reyes 9/12/2020 -->
<title>CNIT 133 Homework 2</title>
<meta charset="utf-8">
<meta name="description" content="homework 2 for CCSF CNIT 133">
<meta name="keywords" content="HTML, CSS, Javascript, CCSF, Student">
<meta name="author" content="Kristian Reyes">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!--bootstrap -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>
<!--bootstrap -->
<script>
function process() { //variable for input function
var number1, number2, number3, number4, number5, n1, n2, n3, n4, n5, countneg, countposi, countzeroes;
number1 = document.forms["myform"].elements["num1"].value;
number2 = document.forms["myform"].elements["num2"].value;
number3 = document.forms["myform"].elements["num3"].value;
number4 = document.forms["myform"].elements["num4"].value;
number5 = document.forms["myform"].elements["num5"].value;
n1 = parseInt(number1); //input numbers 1-5
n2 = parseInt(number2);
n3 = parseInt(number3);
n4 = parseInt(number4);
n5 = parseInt(number5);
countneg = 0; //counter for negative number
countposi = 0; // counter for positive numbers
countzeroes = 0; // counter for zeroes
//input validation to check if value is a number using isNan function. true indicates value is NaN.
if (isNaN(n1) == true || isNaN(n2) == true || isNaN(n3) == true || isNaN(n4) == true || isNaN(n5) == true)
{
alert ("All entries must be NUMBERS! Click RESET and try again.")
}
else
{
// if NaN validation passed, then the rest of the function proceeeds
// if statements repeated for each value that check for positive, negative, and zeroes. The appropriate
// counter is incremented accordingly.
// first number validation
if (n1 > 0)
{
countposi++;
}
if (n1 < 0)
{
countneg++;
}
if (n1 == 0)
{
countzeroes++;
}
// second number validation
if (n2 > 0)
{
countposi++;
}
if (n2 < 0)
{
countneg++;
}
if (n2 == 0)
{
countzeroes++;
}
// third number validation
if (n3 > 0)
{
countposi++;
}
if (n3 < 0)
{
countneg++;
}
if (n3 == 0)
{
countzeroes++;
}
// fourth number validation
if (n4 > 0)
{
countposi++;
}
if (n4 < 0)
{
countneg++;
}
if (n4 == 0)
{
countzeroes++;
}
// first number validation
if (n5 > 0)
{
countposi++;
}
if (n5 < 0)
{
countneg++;
}
if (n5 == 0)
{
countzeroes++;
}
//print statement condensed into one document.forms functions. Displays a new line for each sentence/operation.
document.forms["myform"].elements["results"].value = ("The count of positive numbers is " + countposi + "." + "\nThe count of negative numbers is " + countneg + "."+ "\nThe number of zeroes is " + countzeroes + "." );
}};
</script>
</head>
<body>
<main class="grid">
<header class="grid-area grid-area-1">
<h1>CNIT 133 Homework 2 - Basic Operations </h1>
</header>
<nav class="grid-area grid-area-2">
<ul>
<li>
<a href="homework1.html" title="CNIT 133 - HW 2">
Return to CNIT 133 Homework 2 - Basic Operations
</a>
</li>
</ul>
</nav>
<section class="grid-area grid-area-3">
<h2>Part 3 </h2>
<p> Please enter five numbers below!</p>
<form name="myform">
<table>
<tr>
<td>First Number:</td>
<td>
<input type="text" name="num1" size="10">
</td>
</tr>
<tr>
<td>Second Number:</td>
<td>
<input type="text" name="num2" size="10">
</td>
</tr>
<tr>
<td>Third Number:</td>
<td>
<input type="text" name="num3" size="10">
</td>
</tr>
<tr>
<td>Fourth Number:</td>
<td>
<input type="text" name="num4" size="10">
</td>
</tr>
<tr>
<td>Fifth Number:</td>
<td>
<input type="text" name="num5" size="10">
</td>
</tr>
</table>
<br>
Results:
<br>
<br>
<textarea rows="8" cols="40" name="results"></textarea>
<br>
<br>
<input type="button" onclick="process()" value="SUBMIT">
<input type="reset" value="RESET">
</form>
</section>
<footer class="grid-area grid-area-4">
<p>
© 2020 Kristian Reyes
</p>
</footer>
</main>
</body>
</html>