-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstudent.html
More file actions
56 lines (55 loc) · 1.8 KB
/
student.html
File metadata and controls
56 lines (55 loc) · 1.8 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width,
initial-scale=1.0" />
<title>IP EXP 4 Part 2</title>
</head>
<body>
<h1>IP EXPERIMENT 4</h1>
<h2>Part 2</h2>
<p>To Create a student object and print the details in
JavaScript.</p>
<p>Check the Console for Output</p>
<hr noshade="" />
<p>Input box for error test</p>
<input
id="error_checking"
type="text"
value=""
placeholder="Enter string or 0 for error"
/>
<button type="submit" onclick="return checkError()">Submit</button>
</body>
<script>
// Creating a Student Object
const student1 = {
name: "Vinay",
class_name: "D15A",
roll_no: 29,
};
console.log("Student 1: ", student1);
class Student {
constructor(name, class_name, roll_no) {
this.name = name;
this.class_name = class_name;
this.roll_no = roll_no;
} }
const student2 = new Student("Joey", "D15A", 01);
console.log("Student 2: ", student2);
// Use of Prototype
Student.prototype.nationality = "English";
console.log("Student 2: ", student2);
// Generating an Exception
function checkError() {
const value = document.getElementById("error_checking").value;
console.log(value);
if (isNaN(value) || value == 0) {
throw new Error("Invalid Input ");
} else {
console.log("Valid");
}
} </script>
</html>