Professional Documents
Culture Documents
Q.1 Write A Javascript Program To Validate Form of Vaccination or Covid Test. Program
Q.1 Write A Javascript Program To Validate Form of Vaccination or Covid Test. Program
Q.1 Write A Javascript Program To Validate Form of Vaccination or Covid Test. Program
if (name==null || name==""){
alert("Name can't be blank");
return false;
}else if(password.length<6){
alert("Password must be at least 6 characters long.");
return false;
}
}
</script>
<body>
<form name="myform" method="post"
action="http://www.javatpoint.com/javascriptpages/valid.jsp"
onsubmit="return validateform()" >
Name : <input type="text" name="name"><br/>
Address: <input type="varchar" name="address"><br/>
Contact: <input type="integer" name="contact"><br/>
Aadhar Card: <input type="integer" name="aadharcard"><br/>
Emailid: <input type="varchar" name="emailid"><br/>
Password: <input type="password" name="password"><br/>
<input type="submit" value="register">
</form>
</body>
</html>
Output:
Output:
Q.3 Write a JavaScript program for implementation of Rain Terrraces.
Program:
<script>
function maxWater(arr, n)
let res = 0;
{
left = Math.max(left, arr[j]);
return res;
let arr = [ 0, 1, 0, 2, 1, 0,
1, 3, 2, 1, 2, 1 ];
let n = arr.length;
document.write(maxWater(arr,n));
</script>
Output:
Q4.Write a JavaScript program for implementation of circular queue.
Program:
<script>
// Edit your script here
class CircularQueue{
constructor(size){
this.element=[];
this.size=size
this.length=0
this.front=0
this.back=-1
}
isEmpty(){
return(this.length==0)
}
enqueue(element){
if(this.length>= this.size)throw(new Error("Maximum length exceded"))
this.back++
this.element[this.back% this.size]=element
this.length++
}
dequeue(){
if(this.isEmpty()) throw(new Error("No elements in the queue"))
const value =this.getFront()
this.element[this.front % this.size]=null
this.front++
this.length--
return value
}
getFront(){
if(this.isEmpty()) throw(new Error("No elements in the queue"))
return this.element[this.front % this.size]
}
clear(){
this.element=new Array()
this.length=0
this.back=0
this.front=-1
}
disp(){
for(let i=0;i<this.element.length;i++){
document.write(this.element[i] + " ");
}
document.write("<br>");
}
}
l1=new CircularQueue(5);
l1.disp();
l1.enqueue(29);
l1.disp();
l1.enqueue(21);
l1.disp();
l1.enqueue(27);
l1.disp();
l1.enqueue(21);
l1.disp();
l1.enqueue(24);
l1.disp();
l1.dequeue();
l1.disp();
l1.enqueue(17);
l1.disp();
l1.enqueue(56);
l1.disp();
l1.enqueue();
l1.disp();
</script>
Output:
Q5.Write a JavaScript program for implementation of fast powering
and euclidean.
i) Fast Powering:
Program:
<script>
function pow_num(a,b){
if(a==0) {
retuen 0;
}
ans=1;
while(b !=0) {
if((b & 1) ! =0) {
ans *=a;
}
b >>=1;
a *=a;
}
return ans;
}
A=7; b=13;
document.write(“Power of “+a+” raise to “+b+” is :”
+pow_num(a,b))
</script>
Output:
ii) Euclidean:
Program:
<script>
function gcd( a, b)
{
if (a == 0)
return b;
return gcd(b % a, a);
}
let a = 10, b = 15;
document.write( "GCD(" + a + ", "
+ b + ") = " + gcd(a, b) +"<br/>");
a = 35, b = 10;
document.write( "GCD(" + a + ", "
+ b + ") = " + gcd(a, b) +"<br/>")
a = 31, b = 2;
document.write( "GCD(" + a + ", "
+ b + ") = " + gcd(a, b) +"<br/>");
</script>
Output: