-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
191 lines (128 loc) · 5.06 KB
/
index.html
File metadata and controls
191 lines (128 loc) · 5.06 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
<!DOCTYPE html>
<html>
<head>
<title>Document</title>
</head>
<body>
<button class="btn">click me</button>
<h1>Welcome to javaScript</h1>
<!--alert in js-->
<button onclick="alert('hello welcome')">click me</button>
<!--change html element value-->
<h1 id="idDisplay">How are you ?</h1>
<button onclick="display()">click me</button>
<button onclick="reset()">Reset</button>
<!--add text or sentence to the end of a sentence-->
<h1 id="idAddText">Hello</h1>
<button id="idBtnEnd" onclick="addText()">Click me</button>
<!--Add text to the h1 element-->
<h1 id="idShowText"></h1>
<button onclick="showText()">Click me</button>
<!--change color in a text-->
<h1 style="color: black;" id="idChangeColor">Color Changing</h1>
<button onclick="changeColor()">Click me</button>
<!--hide element-->
<br><br>
<button onclick="hide()">hide me</button>
<h1 id="idHide">I am going to hide</h1>
<!--get user input and show using input-->
<input id="idGetName" type="text">
<button onclick="showInput()">submit</button>
<h1 id="idInputName"></h1>
<!--get user input and show it with additional text-->
<input id="idTextBox" type="text" placeholder="Enter Your Name">
<button onclick="showUserInput()">click me</button>
<h1 id="idOutput"></h1>
<!--create array and show them in console-->
<h2>Arrays in javaScript</h2>
<button onclick="showArray()">click me</button>
<!--if else checking -->
<br><br><br>
<label for="username">User Name : </label>
<input id="idUserName" type="text">
<br><br>
<label for="password">Password : </label>
<input id="idPassword" type="password">
<br><br>
<button onclick="loginPage()">Log in</button>
<!--call seperate html file-->
<h1>Go to another html page</h1>
<button onclick="page2()">Next</button>
<!--random number in Math function-->
<h1>Random Number Check</h1>
<input id="idGetNumber" type="number" min="1" max="10">
<button onclick="randomNumChecker()">play</button>
<script type="text/javaScript">
function display(){
document.getElementById('idDisplay').innerHTML = "I am fine";
}
function reset(){
document.getElementById('idDisplay').innerHTML = "How are You?";
}
function addText(){
document.getElementById("idAddText").innerHTML += " Welcome to JS Practice";
document.getElementById("idBtnEnd").onclick = ""; // remove the button onclick property
}
function showText() {
document.getElementById("idShowText").innerHTML = "Hi welcome to the MERN Stack Developing";
}
function changeColor(){
document.getElementById("idChangeColor").style.color = "red";
}
function hide(){
document.getElementById("idHide").style.display = "none";
}
function showInput(){
let name = document.getElementById("idGetName").value;
document.getElementById("idInputName").innerHTML = name;
}
function showUserInput() {
let name = document.getElementById("idTextBox").value;
document.getElementById("idOutput").innerHTML = "Hello " + name + " !";
}
function showArray(){
// create an array
let array1 = ["apple","samsung","nokia"];
console.log(array1); // display array in console/
// add new element to end of the array
array1.push("huawe");
console.log(array1);
// remove element from array
array1.splice(1,1);
console.log(array1);
// adda new element to the array
array1.splice(1,0, "lts1"); // add new element before the given index
console.log(array1);
array1.splice(1,1, "lts2"); // update the given index with new element
console.log(array1);
array1.splice(1,2, "lts3"); // remove 2 element from given index and update new element
console.log(array1);
}
function loginPage(){
let userName = document.getElementById("idUserName").value;
let password = document.getElementById("idPassword").value;
let uName = "sanchitha";
let pWord = "123";
if (userName == uName && password == pWord ){
alert("Login Successfuly");
}
else{
alert("Login Failed");
}
}
function page2() {
window.location.href = "page2.html";
}
function randomNumChecker(){
let x = document.getElementById("idGetNumber").value;
let y = Math.floor(Math.random()* 2);
if (x == y){
alert("You are Lucky ! Your Number is correct");
}
else{
alert(`you are unlucky ! I guess number ${y}`);
}
}
</script>
</body>
</html>