-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhw6part1.html
More file actions
132 lines (107 loc) · 4.34 KB
/
hw6part1.html
File metadata and controls
132 lines (107 loc) · 4.34 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
<!DOCTYPE html>
<html lang="en">
<head>
<!--Kristian Reyes 11/10/2020 -->
<title>CNIT 133 Homework 6</title>
<meta charset="utf-8">
<meta name="description" content="homework 6 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 calcNumber()
{
var errMsg = "Invalid input, try again.";
if ( isNaN(document.getElementById("number").value) ||
document.getElementById("number").value.length < 4 ||
(document.getElementById("number").value) == "" )
{
document.getElementById("errMsg").innerHTML = errMsg;
}
else {
var sourcenum = parseFloat
(document.getElementById("number").value);
document.myForm.output.value =
"The number you entered is: " + sourcenum +
"\n Your number rounded to the nearest integer: " +
integerRound( sourcenum ) +
"\n The square root of your number, rounded to an integer: " +
squareRound( sourcenum ) +
"\n Your number rounded to the nearest tenth: " +
tenthsRound( sourcenum ) +
"\n Your number rounded to the nearest hundredth: " +
hundredthsRound( sourcenum ) +
"\n Your number rounded to the nearest thousandth: " +
thousandthsRound( sourcenum );
}
}
function integerRound( number )
{
return( Math.round( number) );
}
function squareRound( number )
{
( Math.sqrt( number) );
return number.toFixed(1);
}
function tenthsRound( number )
{
( Math.floor( number * 100 + .5 ) / 10 );
return number.toFixed(2);
}
function hundredthsRound( number )
{
( Math.floor( number * 100 + .5 ) / 100 );
return number.toFixed(3);
}
function thousandthsRound( number )
{
( Math.floor( number * 100 +.5) / 1000 );
return number.toFixed(4);
}
function res() {
document.getElementById("errMsg").innerHTML="";
document.getElementById("number").focus();
}
</script>
</head>
<body onload="document.getElementById('number').focus();">
<main class="grid">
<header class="grid-area grid-area-1">
<h2> Homework 6 - Part 1 </h2>
</header>
<nav class="grid-area grid-area-2">
<ul>
<li>
<a href="homework6.html" title="CNIT 133 - HW 6 ">
Return to CNIT 133 Homework 6 - Objects
</a>
</li>
</ul>
</nav>
<section class="grid-area grid-area-3">
<h2> Part 1</h2>
<div id ="errMsg"></div>
<form name="myForm">
Enter a number with at least 4 decimal positions: <br>
<input type="text" size="30" id="number">
<input type="button" value="Submit" onclick="calcNumber()"><br>
<textarea name = "output" rows = "8" cols = "60" readonly>
</textarea><br>
<input type="reset" value="Reset" onClick="res();">
</form>
</section>
<footer class="grid-area grid-area-4">
<p>
© 2020 Kristian Reyes
</p>
</footer>
</main>
</body>
</html>