MST (New)
MST (New)
WEEK-4D
1. Aim: write a javascript program to create a object using key values. key value to store the
employee details.
<body><script>
</script>
</body><br>
<body><script>
emp.id=104;
emp.name="Ravi";
emp.salary=50000;
</script></body>
Output:
<body><script>
var a = true;
var c = 10;
var d = 10;
document.writeln("c+d: "+(c+d)+"<br>");
document.writeln("x+y: "+(x+y)+"<br>");
document.writeln("c==d: "+(c==d)+"<br>");
document.writeln("x==y: "+(x==y));
</script></body>
Output:
3. Aim: write a javascript program to print correct date and time in a specific part.also print time
alone.
<body>
</script>
<script>
document.getElementById('txt').innerHTML=today;
var h = today.getHours();
var m = today.getMinutes();
var s = today.getSeconds();
document.getElementById('txt1').innerHTML=h+":"+m+":"+s;
</script>
</body>
Output:
4. Aim: write a javascript program to print date in the following format. First line should print
day, second line should print month and third line should print year.
<body><script>
document.writeln("Day:"+d.getDate()+"<br>Month:"+(d.getMonth()+1)+"<br>Year:
"+d.getFullYear());
</script></body>
Output:
<body><script>
window.alert("Hello world");
</script></body>
Output:
6. Aim: write a javascript program to display confirmation alert. When a user clicks on delete
record button.
<body><script>
function msg(){
if(v==true){
alert('ok'); }
else{
alert('cancel'); }}
</script>
</body>
Output:
7.Aim: write a javascript program to enquire what is the user name in a special window and
display ‘I am, username’ after clicking on the clicking button.
<body><script>
function msg(){
Output:
Figure 2: output for after clicks on click button and entering username
8.Aim: write a javascript program to search on or to open google website when a user click on
search button.
<body><script>
function msg() {
open("http://www.google.com"); }</script>
</body>
Output:
Figure 2: output for after clicks on search button and opened google page
9. Aim: write a javascript program to print welcome to javascript after 2000 milliseconds.
Source code:
<body><script>
function msg() {
setTimeout(function(){
Output:
Figure: output displayed when user clicks click button after 2 seconds
10. Aim: write a javascript program to close the window when user clicks on close button.
<body> <script>
function msg( ) {
window.close( ); }
</script>
Output:
document.writeln("navigator.appCodeName: "+navigator.appCodeName);
document.writeln("<br/>navigator.appName: "+navigator.appName);
document.writeln("<br/>navigator.appVersion: "+navigator.appVersion);
document.writeln("<br/>navigator.cookieEnabled: "+navigator.cookieEnabled);
document.writeln("<br/>navigator.language: "+navigator.language);
document.writeln("<br/>navigator.userAgent: "+navigator.userAgent);
document.writeln("<br/>navigator.platform: "+navigator.platform);
document.writeln("<br/>navigator.onLine: "+navigator.onLine);
</script>
document.writeln("<br/>screen.width: "+screen.width);
document.writeln("<br/>screen.height: "+screen.height);
document.writeln("<br/>screen.availWidth: "+screen.availWidth);
document.writeln("<br/>screen.availHeight: "+screen.availHeight);
document.writeln("<br/>screen.colorDepth: "+screen.colorDepth);
document.writeln("<br/>screen.pixelDepth: "+screen.pixelDepth);
</script>
Output:
document.writeln("<br>");
function h() {
</script>
Output:
13. Aim: write a javascript program to count the no: of paragraphs in the given HTML page.
When a user clicks on gthe count button.
<body><script>
function count(){
var total=document.getElementsByTagName("p");
</script>
<button onclick="count()">count</button></body>
Output:
<body> <script>
function fun(){
var total=document.getElementsByName("r");
</script>
<form onsubmit="fun()">
<input type="submit"/>
</form></body>
Output:
15. Aim: write a javascript program to print class executed by the respective HTML program.
<body>
<head>
<h2>Dom methods</h2>
</head>
<div class="class">
<p>Hello world</p>
</div>
<script>
var x=document.getElementsByClassName("class");
</script>
</body>
Output:
WEEK-4B
Aim: Create an Employee class extending from a base class Person. Hints: (i) Create a class
Person with name and age as attributes. (ii) Add a constructor to initialize the values
(iii) Create a class Employee extending Person with additional attributes role.
<body><script>
class person {
constructor(name,age) {
this.name=name;
this.age=age; }
detail() {
constructor(name,age,role) {
super(name,age);
this.role=role; }
show() {
p.show(); p.detail();
</script> </body>
Output:
WEEK-5A
1. Aim: write a JavaScript program to combine arrays into a single array & store it in a new
array.
<body><script>
var arr1=[1,2];
var arr2=[4,6];
var arr3=["Apple","Ball"];
var res=arr1.concat(arr2,arr3);
for(i=0;i<res.length;i++) {
document.writeln(res[i]+"<br>"); }
</script></body>
Output:
2. Aim: write a javascript program to print the student marks greater than 30.
<script>
var marks=[50,40,45,37,20];
function check(value){
return value>30;}
document.writeln(marks.filter(check));
</script>
Output:
3. Aim: write a javascript program to find the first element in the array whose value is greater
than 20.
<script>
var marks=[50,40,45,37,20];
function check(value){
return value>30; }
</script>
Output:
4. Aim: Write a JavaScript program to find the first element index in array whose value is
greater than 20.
<body>
<script>
</script>
</body>
Output:
5. Aim: write a javascript program to find the lastelement value in the array.
<script>
var arr=["c","c++","python","c++","java"];
var res1=arr.lastIndexOf("c++");
Output:
6. Aim: write a javascript program to find the last element value in the array.
<script>
var arr=["c","c++","python","c++","java"];
document.writeln(res1);
</script>
Output:
7. Aim: write a javascript program to add Jquery at the end of the array.
<script>
document.writeln(arr+"<br>");
arr.push("jquery");
</script>
Output:
8 Aim: write a javascript program to add a value at the starting of the array.
<script>
document.writeln("<b>Elements:</b> “arr+”<br>”);
arr.unshift("jquery");
Output:
9. Aim: write a javascript program to remove the last element in the array.
<script>
document.writeln(arr+"<br>");
arr.pop();
Output:
10. Aim: write a javascript program to remove the first element in the array.
<script>
document.writeln(arr+"<br>");
arr.shift();
</script>
Output:
<script>
var arr=[1,2,3,4,5,6,7,8];
document.writeln(“<b>elements:</b>”+arr+"<br>");
arr.reverse();
Output:
<script>
var arr=[4,3,7,5,2,9,1,8,0];
arr.sort();
</script>
Output:
WEEK-5C
Aim: Validate the user by creating a login module. Hints: (i) Create a file login.js with a
User class. (ii) Create a validate method with username and password as arguments.
(iii) If the username and password are equal it will return "Login Successful" else wrong
Source code:
<body>
<script>
class login{
constructor(uname,pwd)
{
this.uname=uname;
this.pwd=pwd;
}
success()
{
if (this.uname == this.pwd)
{
document.writeln("Login Successful");
}
else {
document.writeln("wrong");
}
}
}
var l=new login("rani","rani");
l.success();
</script>
</body>
Output:
WEEK-5B
Output:
console.log(10);
const goodFunc=()=>{
console.log('good'); }
const bestFunc=()=>{
goodFunc();
console.log('best'); }
bestFunc();
Output:
const count=true;
if(count){
console.log(countvalue);
Output:
<html><body>
<div id="foo">
<script>
function changeContent() {
xhttp.onreadystatechange = function() {
document.getElementById("foo")
else { document.getElementById(“foo”)
xhttp.send(); }
</script></body></html>
Output:
Figure 1: output for content changing button Figure 2: output for displaying a message
2.Aim: Simulate a periodic stock price change and display on the console. Hints: (i) Create a
method which returns a random number - use Math.random, floor and other methods
to return a rounded value. (ii) Invoke the method for every three seconds and stop
when.
Source code:
<script>
var time = 3670;
window.setInterval(function(){
var h = Math.floor(time / 3600);
var m = Math.floor(time % 3600 / 60);
var s = Math.floor(time % 3600 % 60);
document.getElementById("demo").innerHTML = h + "h "+ m + "m " + s + "s ";
if (time < 0) {
clearInterval(x);
document.getElementById("demo").innerHTML = "EXPIRED"; }
time--; }, 1000);
</script>
<body><div id='demo'></div></body>
Output: