0% found this document useful (1 vote)
175 views

Ps 1

The document provides the objectives and problems for a JavaScript lab. The objectives are to learn JavaScript variables, operators, control structures, functions, objects, form validation, and event handling. There are 40 problems provided to help students practice these JavaScript concepts. The problems include writing functions to validate data, perform calculations, manipulate text and arrays, create forms and events, and more.

Uploaded by

veralevel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (1 vote)
175 views

Ps 1

The document provides the objectives and problems for a JavaScript lab. The objectives are to learn JavaScript variables, operators, control structures, functions, objects, form validation, and event handling. There are 40 problems provided to help students practice these JavaScript concepts. The problems include writing functions to validate data, perform calculations, manipulate text and arrays, create forms and events, and more.

Uploaded by

veralevel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 6

PSG COLLEGE OF TECHNOLOGY, COIMBATORE -4

DEPARTMENT OF APPLIED MATHEMATICS AND COMPUTATIONAL SCIENCES


III M.Sc DS - 6th SEMESTER
15XD68 - SCRIPTING LANGUAGES LAB
PROBLEM SHEET – 1
Objectives
Client side scripting – Java script:
 To learn to use variables, operators, control structures, functions and objects in
JavaScript.
 To learn how to use Java script to validate form entry.
 To learn to handle user events.
 To learn to create interactive web pages

1. Event Handlers.
a) Create a JavaScript function named welcome that pops up an alert message that says
"Welcome!".
b) Create a button that calls the JavaScript function welcome when the user clicks it.
c) Create a block of text (can be in a div, p, header, ...) that calls the JavaScript function
welcome when the user moves the mouse pointer over it.
2. Write a JS that asks the user about how many random numbers they wish to generate. The
script then generates the numbers and calculates the average of the numbers and returns the
results to the user.

Average of 10 numbers: 0.475


3. Write a JS that asks the user for exactly 10 names and then prints how many names were
entered. The script then sorts the names and prints them in an ordered list. If the cancel
button is pressed the script moves to the next array element and accepts the next name. The
loop doesn't end until ten names or ten hits of the cancel button is done.
4. Define a function max() that takes three numbers as arguments and returns the largest of
them. Use the if-then-else construct available in Javascript.
5. Write a JavaScript function to check whether a given value is IP value or not.
6. Write a JavaScript function to get the current date and test whether it is a weekend and
compute number of days.
7. Write a function that takes a character (i.e. a string of length 1) and returns true if it is a
vowel, false otherwise.
8. Write a pattern that matches e-mail addresses. The personal information part contains the
following ASCII characters.
Uppercase (A-Z) and lowercase (a-z) English letters.
Digits (0-9).
Characters ! # $ % & ' * + - / = ? ^ _ ` { | } ~
Character . ( period, dot or fullstop) provided that it is not the first or last character and it will
not come one after the other.

9. Write a function translate() that will translate a text into "rövarspråket". That is, double
every consonant and place an occurrence of "o" in between. For example, translate("this is
fun") should return the string "tothohisos isos fofunon".
10. Define a function sum() and a function multiply() that sums and multiplies (respectively)
all the numbers in an array of numbers. For example, sum([1,2,3,4]) should return 10, and
multiply([1,2,3,4]) should return 24.
11. Define a function reverse() that computes the reversal of a string. For example,
reverse("jag testar") should return the string "ratset gaj".
12. Represent a small bilingual lexicon as a Javascript object in the following fashion
{"merry":"god", "christmas":"jul", "and":"och", "happy":gott", "new":"nytt", "year":"år"}
and use it to translate your Christmas cards from English into Swedish.
13. You are about to create a JavaScript and HTML program (webpage) which is capable of
computing a student average grades as well returning its equivalent from his/her “First
Prelim,” “Second Prelim,” and “Final” grades. See the following screenshot for your
example:

Note: Name your Input/Output Objects base on its purpose as well your JavaScript
functions and from the result of student average (Semestral Grade); see the following
table for the range of values needed for its “Equivalent”.

Note: You need to create a JavaScript function (for “Compute” button) that will accept
user inputs for First Prelim, Second Prelim, and Final Term text fields as well to perform
a mathematical operation that will return the average of the three values to Semestral
Grade field and its equivalent to the following field. A “Clear” button and its function are
also necessary to prepare your interface for user’s next action. See the following for your
example:
14. Write a JS to perform the operation of a calculator.

15. Form Access and dynamic pages


Create a form that asks the user to enter their name, password, age, phone number and
hometown. When the user presses the Submit button, call a JavaScript function to make
name, password and phone number required fields ,let age and home town optional
fields. The JavaScript function should perform the following actions:
 display the user's name and year they were born (depending on actual date of birth)
on the webpage below the form
 display a link to Google (or Bing) search results for the name of their hometown on
the webpage below the form
 Validate i) phone number contains 10 number of digits ii) name consists of only
alphabets iii) password between 10 and 20 characters long

16. RollOver Image


Use JavaScript to create a rollover image. Choose two images with the same size. Display
one image. When the mouse passes over the image, change it to the second image. When
the mouse leaves the image, change back to the original image. If you can't find two
images that you like, you can use these:
17. Create a HTML form that has no. of text boxes when the form runs in the browser fill the
textboxes with data. Write a script that verifies that all text boxes have been filled, if a text
box has been left empty pop up on alert message indicating which box has been left empty.
When Alerts OK button is clicked, set focus to that specific text box if all the text boxes are
filled display thank you.
18. Create an HTML page which uses JavaScript to Calculate the sum of two durations
given in days, hours, and minutes
19. You have to create a web page that sorts ten numbers entered by a user. The user
initiates the sorting by clicking on a button labeled "Sort in Ascending Order". Your
program will need to use JavaScript to sort the numbers and sorted numbers will then be
placed into a set of output boxes.

20. Write a program to move a text with mouse pointer


21. Deign the following form and validate each field

22. Write a JavaScript code to create a pull down menu box.


23. Write a function filterLongWords() that takes an array of words and an integer i and
returns the array of words that are longer than i.
24. Write a function charFreq() that takes a string and builds a frequency listing of the
characters contained in it. Represent the frequency listing as a Javascript object. Try it with
something like charFreq("abbabcbdbabdbdbabababcbcbab").
25. How would you write any statement using only one write() or writeln() command?
26. Embed JavaScript in HTML document asking users name and then printing Hello
<User_Name>
27. Create a dialogue box creating “Welcome to my website”
28. Write the segment of Script that would ask the user if he wants a greeting message and if
he does, display a Gif file called Welcome.gif and display “Welcome to Netscape Navigator!”
in the document window following the Gif
29. Write the object definition for an object called car with four properties model, make,
year & price.
30. Write a program to display the multiplication table.
31. Write a code to create a scrolling text in a text box.
32. Write a program to change color of the text randomly.
33. Create a web page using two image file which switch b/w one another as the mouse
pointer moves over the image. Use the On Mouse over and On Mouse event handler
34. Use the date function getDate & setDate to prompt the user for an integer b/w 1 – 31 &
return day of the week it represents.
35. Display a time and print message accordingly for eg. Good Morning in Morning etc.
36. Use JavaScript to create a digital clock.
37. Write a program which prompts the user to enter sum of two numbers and display
whether the answer is correct or incorrect.
38. The form consists of two multiple choice list and one single choice list
a. the first multiple choice list display the major dishes available.
b. the second Multiple choice list display the stocks available.
c. The single choice list display the miscellaneous (Milkshakes, soft drinks, softy available etc.)
39. Create a web page with two forms one office copy and one customer copy when the user
enters the date in customer copy it gets updated in the office copy.
40. Write a function the findLongestWord() that takes an array of words and returns the
length of the longest one.
41. Write a JavaScript program to sort an array of JavaScript objects.

Sample Object :

var library = [
{
title: 'The Road Ahead',
author: 'Bill Gates',
libraryID: 1254

},
{
title: 'Walter Isaacson',
author: 'Steve Jobs',
libraryID: 4264
},
{
title: 'Mockingjay: The Final Book of The Hunger Games',
author: 'Suzanne Collins',
libraryID: 3245
}];
Expected Output:

[[object Object] {
author: "Walter Isaacson",
libraryID: 4264,
title: "Steve Jobs"
}, [object Object] {
author: "Suzanne Collins",
libraryID: 3245,
title: "Mockingjay: The Final Book of The Hunger Games"
}, [object Object] {
author: "The Road Ahead",
libraryID: 1254,
title: "Bill Gates"
}]

42. Write a JavaScript function that creates a table, accept row, column numbers from the
user, and input row-column number as content (e.g. Row-0 Column-0) of a cell.

Sample HTML file:

<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>Change the content of a cell</title>
<style type="text/css">
body {margin: 30px;}
</style>
</head><body>
<table id="myTable" border="1">
</table><form>
<input type="button" onclick="createTable()" value="Create the table">
</form></body></html>

You might also like