-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJava Script.html
More file actions
201 lines (168 loc) · 5.61 KB
/
Java Script.html
File metadata and controls
201 lines (168 loc) · 5.61 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
198
199
200
201
<!DOCTYPE html>
<html>
<head>
<h1 align = "center">JAVA SCRIPT</h1>
<title>JAVASCRIPT Tasks</title>
<style>
table,
th,
td {
border-collapse: collapse;
width: 40%;
border: 3px solid black;
text-align: center;
}
</style>
</head>
<body>
<button onclick="JS()">Know more about JavaScript here</button>
<hr>
<table id="table" border="1">
<tr>
<th>Subjects</th>
<th>Marks</th>
</tr>
<tr>
<td>Maths</td>
<td>100</td>
</tr>
<tr>
<td>Physics</td>
<td>80</td>
</tr>
<tr>
<td>Chemistry</td>
<td>95</td>
</tr>
</table>
<h4 id="tot"></h4>
<hr>
<table id="table1" border="1">
<tr>
<th>Subjects</th>
<th>marks</th>
</tr>
<tr>
<td>Data Structures</td>
<td>88</td>
</tr>
<tr>
<td>Python</td>
<td>80</td>
</tr>
<tr>
<td>Java</td>
<td>95</td>
</tr>
<td>C++</td>
<td>75</td>
</tr>
</table>
<h4 id="tot1"></h4>
<h4 id="avg"></h4>
<hr>
<h4>Multiply </h4>
First No :<input id="box1" type="text" oninput="calculate();" />
<br><br>
Second No:<input id="box2" type="text" oninput="calculate();" /><br><br>
Answer :
<input id="result" readonly/>
<hr>
Name :<input type='text' name='text1' id="text1"/>
<input type="submit" name="submit" value="CHECK" onclick="letter()" />
<hr> <h4>a = [1, 2, 3, 4, 5];</h4>
<script>
function JS(){document.write("<h3>JavaScript is a programming language that adds interactivity to your website. This happens in games, in the behavior of responses when buttons are pressed or with data entry on forms; with dynamic styling; with animation, etc. This article helps you get started with JavaScript and furthers your understanding of what is possible.</h3>");}
<!--print two ele in console-->
var x = "Jon";
var y = "BTECH";
console.log("Hey, I am " + x + "" + y);
a = [1, 2, 3, 4, 5];
document.write(
"<h3>Third position element converted to a string : " +
typeof a[2].toString() +
"</h3> "
);
var table = document.getElementById("table"),
sumVal = 0;
c=0
for (var i = 1; i < table.rows.length; i++) {
c=c+1
sumVal = sumVal + parseInt(table.rows[i].cells[1].innerHTML);
}
document.getElementById("tot").innerHTML = "Total Marks = " + sumVal;
var table = document.getElementById("table1"),
sumVal = 0;
c=0
for (var i = 1; i < table.rows.length; i++) {
c=c+1
sumVal = sumVal + parseInt(table.rows[i].cells[1].innerHTML);
}
document.getElementById("tot1").innerHTML = "Total Marks = " + sumVal;
document.getElementById("avg").innerHTML = "Averagel Marks = " + sumVal/c;
function calculate() {
var myBox1 = document.getElementById('box1').value;
var myBox2 = document.getElementById('box2').value;
var result = document.getElementById('result');
var myResult = myBox1 * myBox2;
document.getElementById('result').value = myResult;
}
function letter()
{
var inputtxt = document.getElementById('text1').value;
var letters = /^[A-Za-z]+$/;
if(inputtxt.match(letters))
{
alert('Name approved :');
}
else
{
alert('Only alphabets are to be entered');
}}
<!--math operations-->
function pow(){
var num = parseInt(document.getElementById('num').value);
var pow = parseInt(document.getElementById('power').value);
r=Math.pow(num,pow)
document.write ( "<h4>power("+num+" , "+pow+") =" +r+"</h4>");
return true;
}
function sqrt(){
var num = parseInt(document.getElementById('num1').value);
r=Math.sqrt(num)
document.write ( "<h4>square root("+num+") =" +r+"</h4>");
return true;
}
function abs(){
var num = parseInt(document.getElementById('num2').value);
r=Math.abs(num)
document.write ( "<h4>absolute value("+num+") =" +r+"</h4>");
return true;
}
function rand(){
var rand=Math.random();
document.write ( "<h4>random number := " +rand+"</h4>");
document.write ( "<h4>multiply by 100 := " +(rand*100)+" </h4>");
document.write ( "<h4>floor := " +Math.floor(rand*100)+" </h4>");
document.write ( "<h4>ceil := " +Math.ceil(rand*100)+" </h4>");
document.write ( "<h4>cos() := " +Math.cos(rand*100)+" </h4>");
document.write ( "<h4>sin() := " +Math.sin(rand*100)+" </h4>");
return true;
}
</script>
<hr>
<h3><u>Math operations</u></h3>
<h4>power of numbers</h4>
Enter Number :<input type="text" id="num"/>
Enter Power :<input type="text" id="power"/>
<input type="submit" name="submit" value="CLICK" onclick="pow()" />
<h4>square root of number</h4>
Enter Number :<input type="text" id="num1"/>
<input type="submit" name="submit" value="CLICK" onclick="sqrt()" />
<h4>Absolute Number</h4>
Enter Number :<input type="text" id="num2"/>
<input type="submit" name="submit" value="CLICK" onclick="abs()" />
<h4>random Number</h4>
<input type="submit" name="submit" value="Generate" onclick="rand()" />
</body>
</html>